ACC1x: How to Find a Record Using a Bound Control (1.x)Last reviewed: May 14, 1997Article ID: Q105660 |
The information in this article applies to:
SUMMARYThis article demonstrates how to use a single bound control for both data entry and for finding records in a form. You can use this technique to find whether the value entered in a field already exists in another record. If the value does exist, the record containing that value will be displayed. If the value does not exist, you can continue entering data for the new record. This article assumes that you are familiar with Access Basic and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information on Access Basic, please refer to the "Introduction to Programming" manual.
MORE INFORMATIONThe Microsoft Access "User's Guide" demonstrates a method that you can use to find records in your database by selecting a key value from a list. (See "Finding a Record by Selecting a Value from a List.") This method is limited in that it requires two controls. One control is an unbound control that is used to select the value to look for, and the other control is a bound control in which data entry for that value occurs. The following example demonstrates how to use a single, bound control to achieve the same functionality:
How the Sample Functions WorkThe FindBeforeUpdate() function uses the FindFirst method to search the dynaset the form is based on to see if the value entered in the control exists in the table. If the value does not exist, the global variable Found is set to NULL and the function exits. If the value does exist, the global variable Found is set to the bookmark of the found record to be used by the FindOnExit() function. Before the FindRecord action can be run, the BeforeUpdate event must be canceled, and a SendKeys action must send two ESC keys to undo changes to the current record. Next, a SendKeys action sends a TAB key to exit the field. This event triggers the FindOnExit() function, which checks to see if the find was successful. If it was, the CancelEvent action is run to prevent exiting the control, and then the form record is synchronized with the found record by setting its bookmark equal to the bookmark of the found record. Found is then reset back to NULL.
REFERENCESMicrosoft Access "User's Guide," version 1.0, pages 547-548 Microsoft Access "User's Guide," version 1.1, pages 551-552 |
Keywords : GnlDe kbusage
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |