How to run a query from a comboBox event? (1 Viewer)

Diango

Registered User.
Local time
Today, 12:51
Joined
Sep 6, 2007
Messages
19
I would like to run a query where I have a comboBox that carries ID's, if I select an ID, then I want to be able to use that selected ID to perform a Select query which will show the results in a textbox.
 

RuralGuy

AWF VIP
Local time
Today, 13:51
Joined
Jul 2, 2005
Messages
13,825
Use the AfterUpdate event of the ComboBox and use a DLookup() function for your query.
 

Diango

Registered User.
Local time
Today, 12:51
Joined
Sep 6, 2007
Messages
19
How do I place that in a TextBox? Is it better to use DLookUP to query a table rather than CurrentDb.Execute?
 

Diango

Registered User.
Local time
Today, 12:51
Joined
Sep 6, 2007
Messages
19
This is the code I have to run that query and it's coming back with an error, something about canceling the previous operation.

Private Sub cmbID_AfterUpdate()
Dim strQuery As String
Dim Value As String

Value = cmbID.Value

strQuery = DLookup("[2007_Term_GPA]", "Undergrad", "ID=" & Value)
End Sub

2007_term_gpa is my column, Undergrad is the name of my table.
 

Diango

Registered User.
Local time
Today, 12:51
Joined
Sep 6, 2007
Messages
19
Weird, I'm still getting the same error.
 

RuralGuy

AWF VIP
Local time
Today, 13:51
Joined
Jul 2, 2005
Messages
13,825
If ID is a string or text field then use the following:
strQuery = DLookup("[2007_Term_GPA]", "Undergrad", "ID='" & Me.cmbID & "'")
If any of the arguments in the DLookup() function are not correct or misspelled then you will get the error you mentioned.
 

Users who are viewing this thread

Top Bottom