Accessing query through vb

  • Thread starter Thread starter Dan
  • Start date Start date
D

Dan

Hi,

I am trying to open a query through vb and copy its data
to be transfered into an excel spread sheet, but I get an
error message "There was an error executing the command."
when the program reaches set rst = qd.OpenRecordset. I
can not figure out why I am getting this. The code I
have so far is:


Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim qd As DAO.QueryDef
Dim varResults

Set db = CurrentDb
Set qd = db.QueryDefs("qry_Backlog For V-Cone")
Set rst = qd.OpenRecordset '<----!!!Crashes here!!!

varResults = rst.GetRows(800)

rst.Close
Set rst = Nothing
Set qd = Nothing
Set db = Nothing

Does anybody know why? How can I fix this?

Thank you.
 
The syntax used in the Help file would be:

Set rst = qd.OpenRecordset ()

(i.e., try adding a pair of empty parentheses)
 
Back
Top