Finding Matching Records in Data Access Pages - Using Combo boxes to find records
(Page 4 of 4 )
Since the previous example has been described in considerable detail, only some relevant screen shots will be shown and the coding will be similar to the previous example except that instead of a textbox there will be two combo-boxes whose properties will be set in such a way that they get populated by the EmployeeID in one, and by FirstName in the other. Again the code will be written to those elements by following up their ids in the "Document Outline."
The design view of Employees.htm
The next picture shows the design view of the Employee.htm which has a different recordset. Two combo-boxes have been added to this page, the same way the textbox was added in the previous example. Their labels have been changed to reflect what is achieved by picking something from the combo-box. The picture also shows the setting for one of the combo-boxes (EmployeeID). The drop-down list has an ID property. The combo-box gets tied to the EmployeeID field and since its source is Recordset:Employees, when the page is shown in preview, the combo-box gets populated by the EmployeeID. In a similar way, the FirstName combo-box gets populated by the Employee First Names.

The code for finding the specified FirstName
The FirstName combo box has been given an id, Ename. The next picture shows the vbscript code for the onchange event of this object. When you write the code make sure the id matches correctly as shown. Again the routine for finding the Ename is the same except that the combo-box's onchange event is used and the code is written for this event. The Find() method can take three other optional arguments.
Testing this code
Open the page using the View menu option. By choosing a FirstName or an EmployeeID name, you can bring up the record corresponding to that FirstName or the EmployeeID as shown for the Employee whose FirstName is Steven. It may be noticed that the navigation control is hidden, which you can do in the design. However the navigation will be effective if you want to use because it is bound to the recordset.

Summary
It is quite easy to find records bound to Data Access Pages using the Recordset's Find() method as shown in this article. If you need to hide data from prying eyes you may just have an empty textbox, but now you need to enter the correct information. No validation has been set for the textbox, which you must include to prevent runtime error in your code. Both examples could be implemented in the same DAP. It was shown separately in this tutorial for reasons of clarity.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |