ACC2: How to Find a Record Using a Bound ControlLast reviewed: May 14, 1997Article ID: Q115189 |
The information in this article applies to:
SUMMARYModerate: Requires basic macro, coding, and interoperability skills. This article demonstrates how to use a single bound control both for finding records and entering data 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 in another record, the record containing that value will be displayed. If the value does not exist in another record, you can continue entering data for the current 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 "Building Applications" 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. NOTE: The field to which the control is bound cannot be a required field and it cannot have a validation rule that allows null values. Make sure that the field's Required property is set to No and that its ValidationRule property does not allow null values.
How the Sample Functions WorkThe Find_BeforeUpdate() 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 Find_OnExit() function. Before the found record can be presented, the BeforeUpdate event must be canceled, and a SendKeys action must send two ESC keys to undo changes to the current record. Next, the SendKeys action sends a TAB key to exit the field. This event triggers the Find_OnExit() 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 2.0, Chapter 25, "Using Macros and Forms," pages 651-652
|
Additional query words: findrecord
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |