Monday, November 21, 2016

PRINT A REPORT FROM A FORM MICROSOFT ACCESS WITH WHERE CONDITION


Table name : Personnel_details (name_id,personnel_name dob, position)
                   : Section ( name_id ,personnel_name, section)

Query name : section_query (position_name, position, section)

Form name : Form1


First, I create  a new blank form and create a combo box contains personnel name from personnel table. Then create command button named Report.


 After that  edit property sheet of the button. Choose menu event then choose macro builder for on click.  Add new action OpenReport. This action can restrict the records that are printed in the report by using Where Condition. Where conditions  is a valid SQL WHERE clause (without the word WHERE) or expression that Access uses to select records from the report's underlying table or query.

To open a report and restrict its records to those specified by the value of a control on a form, use the following expression :
[fieldname] = Forms![formname]![controlname on form]

Ex: [sectionquery]![personnelname] = Forms![Form1][Command0]