Steven
Steven

Reputation: 155

Access VBA Receiving an Error on OpenRecordset

Dim recvar
Dim addrvar
Dim grpvar
Dim rst As Recordset
Dim db As dao.Database
Dim findExisting

recVar = Forms!locspecificinfofrm.ActiveDataSubfrm!Record_ID.Value
grpVar = Forms!locspecificinfofrm.Location!Grp_ID.Value

findExisting = "SELECT [Addr_ID] FROM [Prov_Address_Bridge] WHERE 
[Record_ID] = " & recVar & " AND [Grp_ID] = " & grpVar & " AND [Addr_Type] = 'Remit'"

Set rst = db.OpenRecordset(findExisting)

I'm receiving the following error:

Runtime Error 91: Object variable or with block variable not set

Initially I thought it was treating my last line like this:

set rst = nothing

But the variables that I'm using to test the query should pull something, I just keep getting this error. The strange thing is I use this same snippet of code in other events on the same form and it works fine.

Upvotes: 0

Views: 1631

Answers (2)

Jorge Omar Medra
Jorge Omar Medra

Reputation: 988

Pelase, specify the line which raises the error. I'm assuming that the error is in the line with code:

Set rst = db.OpenRecordset(findExisting)

As I see, in your code you are not set an instance to db like this:

Set db = CurrentDb 

or, for example

Set db = wrkAcc.OpenDatabase("YourDatabase")  

Use your debug yo see if the variable db is not in Nothing. If it is you must set in db variable the correcto instance of dao.Database.

Upvotes: 0

BobNoobGuy
BobNoobGuy

Reputation: 1645

You need to set db

Set db = CurrentDb

Upvotes: 2

Related Questions