ACC: How to Find a Record Using a Bound Control (95/97)Last reviewed: August 28, 1997Article ID: Q136123 |
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 for both finding records and for 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 is 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 Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to your version of the "Building Applications with Microsoft Access" manual.
MORE INFORMATIONThe Microsoft Access online Help system demonstrates how to use the Combo Box Wizard to find records in your database by selecting a key value from a list. (See "Value List," and then "Finding a Record by Selecting a Value from a List" in the Microsoft Access Help system.) This method is limited in that it is designed to be used with a control not based on any table or query (unbound control). 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. To use a single bound control for both finding records and for entering data in a form, follow these steps:
How the Sample Functions WorkThe Find_BeforeUpdate() function uses the FindFirst method to search the recordset 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.
REFERENCESFor more information about this topic in Microsoft Access version 2.0, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q115189 TITLE : ACC2: How to Find a Record Using a Bound Control Keywords : JetFind kbusage PgmHowTo FmsHowTo FmsEvnt Version : 7.0 97 Platform : WINDOWS Hardware : x86 Issue type : kbhowto |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |