
Executing Access queries with Data Control and parameter passing
I am trying to execute an Access query from a VB program. The Access query needs a parameter setting in its condition clause. I do
this with the following program. But still I cannot link the results to a Data Control. The following should work but doesn't:
Dim MyDB As Database, MyQuery As QueryDef
Set MyDB = OpenDatabase("h:\vb3\biblio2.MDB")
Set MyQuery = MyDB.OpenQueryDef("By state")
MyQuery![Enter State] = "NY" ' Set parameter.
Data1.RecordSource = MyQuery.SQL
Data1.Refresh
I get an error on the last command saying "1 parameter expected but 0 returned" or something similar. While I know that the query
gives more than one row result (with a print loop). Strange! Anybody out there who has an idea how to link the query result to a data
control?
Thanks,
Pjotr van Schothorst