Run time error 91

C

ctdak

Program execution stops at

Set rs = CurrentDb.OpenRecordset(strQuery, dbOpenSnapshot)

I get Run-time error 91, “Object variable or With block variable not setâ€

I have Dim statements
Dim rs As Recordset
Dim CurrentDb as Database (I added this one to test, but it didn’t help

Any idea why I am getting this error

ctdak
 
J

Jamie

Try:

Dim rs As DAO.Recordset
Dim db as DAO.Database
Dim strQuery as String

strQuery = "ENTER SQL HERE"
Set db = Access.CurrentDB
Set rs = db.OpenRecordset(strQuery, DAO.dbOpenSnapshot)
'ETC, ETC
rs.close
set rs = Nothing
db.close
set db = Nothing

Jamie
 
C

ctdak

Jamie
Thanks very much for your help. I'm new at VBA code and had not done anything with DAO or recordsets before. I don't believe I will do the "db.close" though because that would be closing the current database that I'm working in
ctda

----- Jamie wrote: ----

Try

Dim rs As DAO.Recordse
Dim db as DAO.Databas
Dim strQuery as Strin

strQuery = "ENTER SQL HERE
Set db = Access.CurrentD
Set rs = db.OpenRecordset(strQuery, DAO.dbOpenSnapshot
'ETC, ET
rs.clos
set rs = Nothin
db.clos
set db = Nothin

Jami
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top