Just to further clarify; when you find the OnClick event, make sure you choose [Event Procedure] and then click the Code Builder button on the right (looks like a little button with three dots on it).
Main Topics
Browse All TopicsI have a form with a textbox and command button. The textbox captures a search string. The command button's OnClick event launches a query to return matches of the search string, rather like google.
Query (or match) results are dispalyed in a subform. I want to click on a numeric key value returned in the subform, in order to display related records from a second form. I was given the following code:
Private Sub YourField_Click()
DoCmd.OpenForm "YourSecondForm", , "customer_number=" & customer_number
End Sub
(Please see complete thread: Q_21755175.html)
I don't know how to do this. Do I create a module? If I do it in subform "properties" the subform only appears to allow OnEnter and OnExit events. I can't figure out how to create an OnClick event for a field in the subform.
In YourField the corresponding filed in the second form? If so, I don't think this code works.
thanks, rene'
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Thanks mgrattan. But this is what's killing me.
The subform's record source is a query. If I place the cursor in the subform while in design view, then select View/Field List from the toolbar, I can see the field (from the record source query) I wish to click on. But I can't open a Properties box for any of these fields. Double clicking on a field does nothing. Right clicking on a field does nothing.
Is there maybe a bug in our Access install?
The subform only appears to allow OnEnter and OnExit events for the entire subform, and no properties for select fields in the subform. I don't have the option of setting an event property for just one field.
I think I tried putting hte following in the code for the main form. It didn't work with this syntax, but I'm thinking it might be made to work. If you agree, what does "YourField" represent in the code below?
Private Sub YourField_Click()
DoCmd.OpenForm "YourSecondForm", , "customer_number=" & customer_number
End Sub
Is the subform a Continuous Form that displays several search results? If so, do the following:
- Open the subform in design view separately from the main form; i.e., make sure the main form is completely closed and then find the subform in your database window and open only the subform in design view.
- Looking at the subform in design view, do you have text boxes layed out on the subform? Is one of the those text boxes the one you want to click and trigger an event procedure?
- Double-click the text box that represents the field you want to use for the event procedure. Look in the Events tab and find the OnClick event. If the event is not listed still, then I believe there might be something else wrong with either the Access project or possibly your installation.
Let me know.
Also, if you want me to look at the database project you can email it to me (roccklobster at gmail dot com).
It shouldn't matter that the subform recordsource is a query. It also shouldn't matter if the fields are bound or not. The event procedures should still be the same. Go ahead and email a zipped copy of the app and I'll take a look at it. Please indicate in your email exactly which form(s) you need help with and which field(s) in the forms need to be worked on.
Thanks.
I've looked at your database and found the following:
- The subform wasn't an Access Form object; instead, it was an embedded query, which won't behave like a form and does not have the same events.
- I built a sample subform for you and set it up to display as a Datasheet. If you look at the subform's design, you will see that text boxes represent the fields in the underlying query. These text boxes have events. I've set up a sample in the NUMBER
Business Accounts
Answer for Membership
by: mgrattanPosted on 2006-03-06 at 13:52:17ID: 16118930
Open your subform in Design view and double-click the Field you want to use for the event. In the field's Properites window, find the OnClick event and add your code there.