Run time error 91

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 
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
 
Back
Top