Create an Unbound Form
|Figure 1: The form to collect our Query Parameters.|
- Click the FORM DESIGN icon. This is located in the FORMS group on the CREATE tab of the Access Ribbon.
- Add the first text box to the form by clicking the TEXTBOX icon from the CONTROLS group and clicking on the desired position on the design grid.
- Select the textbox by clicking it and then click the PROPERTIES icon to bring up the PROPERTIES sheet. Select the OTHER tab from the sheet.
- We are going to refer to this text box as txtFirstName. To do this we need to type FIRSTNAME into the NAME property of the PROPERTIES SHEET.
- Next add a second text box to the form.
- Select the 2nd Textbox and enter txtSurname as the NAME property on the PROPERTIES SHEET.
- Now we need to select the whole form by clicking the small square at the top left hand corner of the design grid. We are going to change some of the form properties to make the form look like a Dialogue box.
- Select the FORMAT tab of the PROPERTIES SHEET.
- Change the RECORD SELECTORS property to NO.
- Change the NAVIGATION BUTTONS property to NO.
- Change the BORDER STYLE property to DIALOG.
- Select the OTHER tab of the PROPERTIES SHEET.
- Change the POP UP property to YES.
- Finish by saving your form as frmEnterParameter.
- Click the QUERY DESIGN icon to create a new query.
- Select the customer table you just created from the SHOW TABLE dialogue box.
- Select the fields to be used in the query. The quickest way of doing this is to double click each field name from the table box located above the design grid. The fields to be used are ID, FirstName, and Surname.
- We now need to enter the query criteria. To do this we are going to reference the parameter text boxes on the form we created earlier. On the Query Design Grid, enter the following syntax in the criteria row of the FirstName and Surname columns respectively.
The parameters entered by the user at runtime will then be used by Access as the Query Criteria.
|Figure 2: The Query Design.|
Now that we have created our query, we can go back to the form we created earlier and add a command button which runs the query when clicked. To do this we are going to use the COMMAND BUTTON WIZARD. Here is the procedure.
- Open the form we created earlier in DESIGN VIEW.
- Ensure the USE CONTROL WIZARDS icon is selected. It is located in the CONTROLS group of the DESIGN ribbon, and should be highlighted in orange.
- Click the BUTTON CONTROL icon (from the CONTROLS group), and position it on the design grid. When you click on the desired position, the COMMAND BUTTON WIZARD begins.
Figure 2: The Command Button Wizard.
- Click MISCELLANEOUS for the category, and RUN QUERY for the Action. Then click NEXT.
- Highlight the name of the Query we want to run. The one we created earlier was called qryNameSearch. Click NEXT.
- Choose whether you would like text or a picture to be displayed on the command button. Click NEXT.
- Enter a meaningful name for the Command Button. Lets call ours ctlRunQuery.