How to Open a Selected Contact Record from an Access Subform
Question details
The user wants to open a specific contact record by double-clicking it in an Access subform but encounters a 'Method or data member not found' compile error.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- Triggering a VBA event to open a related form based on a selected record in a subform.
- Observed behavior
- A compile error occurs referencing the CustID# field, preventing the Contacts form from opening.
Verify that the fields you are referencing in your VBA code exist as controls on your subform and that the target form is correctly named in your database.
Bind the Event to the Specific Control Rather than the Subform
Attach the double-click event directly to the ContactID control instead of the entire subform to accurately target the selected record.
Applying the double-click event to the entire subform can lead to unexpected behaviors or reference errors. Binding the event specifically to the unique identifier control ensures that the command executes exactly on the row the user clicked.
Open your Microsoft Access database, right-click the contacts subform in the Navigation Pane, and select Design View.
Right-click the ContactID text box control (not the form background) and select Properties to open the Property Sheet.
Navigate to the Event tab on the Property Sheet, click on the On Dbl Click property, select [Event Procedure] from the dropdown, and click the ellipsis (...) button.
In the VBA editor, enter the following command: DoCmd.OpenForm FormName:="Contacts", WhereCondition:="ContactID = " & Me.ContactID
Save your form, switch to Form View, and double-click the ContactID field to ensure the targeted Contacts form opens correctly.

Format Field Names with Special Characters Using Brackets
If your VBA code references field names containing special characters like the pound sign (#), you must enclose them in square brackets to prevent compile errors.
Manage Your Data with WPS Office
While Microsoft Access handles complex relational databases, many users find that managing contacts and customer lists is much easier in a spreadsheet environment. WPS Office provides a free, lightweight, and highly compatible alternative for your daily data management needs without the hassle of complex VBA coding.
- 1. Download WPS Office: Download and install the WPS Office suite for free from the official website.
- 2. Open WPS Spreadsheet: Launch WPS Spreadsheet and create a new workbook for your data.
- 3. Import Your Data: Easily import your existing contact lists from CSV or Excel formats to start managing your records without complex databases.

Frequently Asked Questions
Why do I get a 'Method or data member not found' error in Access VBA?
This compile error usually occurs when your VBA code references a field or control that does not exist on the current form. It can also happen if the referenced field name contains a special character, causing the VBA compiler to misinterpret the reference.
Are special characters allowed in Microsoft Access field names?
While Microsoft Access does technically allow characters like the pound sign (#) in field names, it is highly discouraged. Special characters can cause syntax errors in VBA modules and SQL queries unless explicitly wrapped in square brackets (e.g., [CustID#]).
How do I filter an Access form to a specific record via VBA?
You can use the DoCmd.OpenForm method combined with the WhereCondition parameter. For example, supplying WhereCondition:="ContactID = " & Me.ContactID instructs Access to open the target form filtered exclusively to the record that matches the selected ID.




