Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dynamic query failing

Status
Not open for further replies.

ugly

Programmer
Joined
Jul 5, 2002
Messages
70
Location
GB
My form has two list boxes. The user selects a value in listbox1, based on this value I would like a dynamic query to pull in the values then to populate listbox2 with them.
I inserted the following code into Listbox1’s Click event

Private Sub List1_Click()
Dim hold As String
hold = Me.List1.Value
'DoCmd.RunSQL ("SELECT FROM drawings WHERE drawings.[drawingNo] = " & hold & ";")
End Sub

Hold is returning the correct string but the sql is failing and I’m not sure why?
Also how do I associate the returned values with listbox2 so that they appear in listbox2.
Thanks for your time-
 
If "hold" is a string it needs to be enclosed in single quotes:
("SELECT FROM drawings WHERE drawings.[drawingNo] = '" & hold & "'")
As to the second question, you will either need to open a recordset or use DLookup to extract the data item. Both are well documented in Access help.....


Did you hear about the Buddhist who refused Novocain during a root
canal? He wanted to transcend dental medication.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top