How to get query input from second source if first is blank

Idris01

New member
Local time
Today, 21:34
Joined
Jun 10, 2011
Messages
9
Hi, I have a form which displays records based on a Unique identifier, the problem i have is that users may not always have the number so will have to search for it. I can get the query to see the entry in the search combo box, but if they know the number and enter into a text box without using the combo search how can i get the query to open the form using this number?

Thanks in advance
 
how can i get the query to open the form using this number?

This is a little unclear because a query doesn't open a form. I'm going to assume you mean the results of the query are based on the selection in the combo box.

If so, here is one possible solution. You have a form that uses the query as it's record source, with an unbound combo box displaying the list of possible unique values, and an unbound text box (another assumption on my part based on your post). Instead of having the query use the combo box as a parameter, have it use the text box instead. In the After Update event of the combo box, put;

Code:
Me!YourTextBox = Me!YourComboBox
Me.Requery

Replacing YourtextBox and YourComboBox with the actual names of your controls of course.

Note: If the unique identifier is not in the bound column, usually Column(0), of your combo box, then you'll have to modify the code to use the Column method, like;

Code:
Me!YourTextBox = Me!YourComboBox.Column([I]n[/I])
Me.Requery

Where n represents the index of the appropriate column in the combo box.

Then, in the After Upate event of the text box, just requery the form;

Code:
Me.Requery

When a value is selected in the combo box, it will appear in the text box and the form will be requeried in the combo box After Update event. However, the user will also have the option of manually entering a value in the text box. The After Update event of the text box will requery the form after the manual entry of a value. In case you're wondering, the After Update event of the text box will not fire when the value is placed there by the combo box event.
 

Users who are viewing this thread

Back
Top Bottom