Object variable or With block variable not set (Error 91)

?

********

I get an error "Object variable or With block variable not set (Error 91)"
on this statement in the code Set rs = db.OpenRecordset(strSQL).
What's wrong? Thanks.


Private Sub db_betw_dates_obj_MouseDown(Button As Integer, Shift As Integer,
X As Single, Y As Single)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String

strSQL = "select * FROM roncheck_access" _
& "where [DATE] Between " _
& "#[start_date_cal.value]# And #[end_date_cal.value]#;"
Set rs = db.OpenRecordset(strSQL)
End Sub
 
B

Brian

******** said:
I get an error "Object variable or With block variable not set (Error 91)"
on this statement in the code Set rs = db.OpenRecordset(strSQL).
What's wrong? Thanks.


Private Sub db_betw_dates_obj_MouseDown(Button As Integer, Shift As Integer,
X As Single, Y As Single)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String

strSQL = "select * FROM roncheck_access" _
& "where [DATE] Between " _
& "#[start_date_cal.value]# And #[end_date_cal.value]#;"
Set rs = db.OpenRecordset(strSQL)
End Sub

You haven't set the variable "db" e.g.

Set db = CurrentDb
 
J

Jonathan Parminter

-----Original Message-----
I get an error "Object variable or With block variable not set (Error 91)"
on this statement in the code Set rs = db.OpenRecordset(strSQL).
What's wrong? Thanks.


Private Sub db_betw_dates_obj_MouseDown(Button As Integer, Shift As Integer,
X As Single, Y As Single)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String

strSQL = "select * FROM roncheck_access" _
& "where [DATE] Between " _
& "#[start_date_cal.value]# And #[end_date_cal.value] #;"
Set rs = db.OpenRecordset(strSQL)
End Sub

.
Hi Ali,
in addition to Brians observation to swop
db.openrecordset with
currentdb.openrecordset

you might like to revise your strSQL as you seem to be
including references to fields/controls as literals. That
is,...

strSQL = "select * FROM roncheck_access" _
& "where [DATE] Between " _
& "#" & start_date_cal.value & "# And #" &
end_date_cal.value & "#;"

Luck
Jonathan
 

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