PDA

View Full Version : Query Error



kbsudhir
12-17-2008, 07:16 AM
Hi All

I am writing teh below query to get data from my access database using VBA

rs2.Open "SELECT LeavePlanner.Name FROM LeavePlanner WHERE (((LeavePlanner.Name)='" & CSname & "') AND ((LeavePlanner.LeavesStartDate)<=#Date()#) AND ((Format([LeavesStartDate],'" & m & "'))=Format(#Date()#,'" & m & "'))) GROUP BY LeavePlanner.Name;", cn, adOpenStatic, adLockReadOnly

But when this code is executed I am getting an error:

Runtime error '91':
Object variable or with block variable is not set.

PLease guide what am i doing wrong in this line of code.

Thanks
Sudhir

CreganTur
12-17-2008, 09:46 AM
Is rs2 an ADO or DAO recordset? Can you show us more of the code?

The error you're getting means that an object variable- a variable to hold a reference to an object- was not declared correctly, or you've got a With that's missing its End With.

kbsudhir
12-19-2008, 08:05 AM
I am using ADO recordset.

CreganTur
12-19-2008, 08:23 AM
Please post the whole code- I really can't tell anything from what you've given us. The syntax looks correct, but I can't be sure because I don't know the value of cn.

kbsudhir
12-19-2008, 08:39 AM
Hi Randy,

I am looking what you told "you've got a With that's missing its End With",
I will reply after some testing.

Thanks for the guidance.

Sudhir