MS Access 2007 SQL Statement (1 Viewer)

Sigma248

Registered User.
Local time
Yesterday, 22:04
Joined
Oct 6, 2008
Messages
24
Can anyone tell me what is wrong with this SQL Satement when used in a MS Access 2007 CurrentDB.OpenRecordset command.

("SELECT tStatusChanged.AddressNumber, tStatusChanged.StatusNumber, tStatusChanged.StatusChangedDate" _
& " FROM tStatusChanged" _
& " WHERE tStatusChanged.StatusChangedDate <=#" & Format(tempDate, "mm/dd/yyyy") & "#" _
& " ORDER BY tStatusChanged.AddressNumber, tStatusChanged.StatusNumber")

Where tempDate is a Date type variable.

I am pretty sure its the <= that's incorrect but I am not sure what it should be.

Thanks.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 22:04
Joined
Aug 30, 2003
Messages
36,139
Do you get an error? Unexpected results?
 

Sigma248

Registered User.
Local time
Yesterday, 22:04
Joined
Oct 6, 2008
Messages
24
I get unexpected results. An empty recordset when I should get a recordset with some records.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 06:04
Joined
Sep 12, 2006
Messages
15,744
why dont you design your query as a stored query

then just

docmd.openrecordset "mystoredquery"


--------
its far easier to design a query visually, than write the SQL, and you can see the results you get.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 22:04
Joined
Aug 30, 2003
Messages
36,139
Have you set a breakpoint to make sure the date variable contains what it should? <= should work fine.
 

Sigma248

Registered User.
Local time
Yesterday, 22:04
Joined
Oct 6, 2008
Messages
24
Thanks everyone, got it working, the >= is correct.
:D
 

Users who are viewing this thread

Top Bottom