comparing dates

grenee

Registered User.
Local time
Today, 08:30
Joined
Mar 5, 2012
Messages
212
Good day all,

My code is intended to compare dates in my table with todays date. However I am not getting the desire results from this code, because the table contains todays date and yet no results are returned:

Code:
 DoCmd.OpenForm "Edit Signin", acNormal, , "OfficerName = '" & WorkersName & "' And (tblSignin.DateCreated) = # " & Date & "#"

can some examine this code for me please?
 
remove leading space on the first hash (#):

DoCmd.OpenForm "Edit Signin", acNormal, , "OfficerName = '" & WorkersName & "' And [DateCreated] = #" & Date & "#"
 
Thanks Arnelgp; however I am still not getting the expected results.
I have todays dates in the table but the expected records are still not returning.
I gone on to do a little test to show me what is actually in the "DateCreated" field and to my supprise all the values in the field are recognized as NULL.
Here is my original and additional code:

Code:
DoCmd.OpenForm "Edit Signin", acNormal, , "OfficerName = '" & WorkersName & "' And (tblSignin.DateCreated) = #" & (Date) & "#"
MsgBox Nz(Forms![Edit SignIn]![tblSignIn.DateCreated], "Test")
MsgBox Date

The 1st Msgbox displays today's date; the 2nd Msgbox displays "Test"
I even tried wrapping "DateCreated" and "Date" with DateValue, to no avail
 
Last edited:
sooo, if timestamp is not included in your DateCreated field:

DoCmd.OpenForm "Edit Signin", acNormal, , "OfficerName = '" & WorkersName & "' And [DateCreated] = #" & Format(Date(),"mm/dd/yyyy") & "#"

if it does:

DoCmd.OpenForm "Edit Signin", acNormal, , "OfficerName = '" & WorkersName & "' And DateValue([DateCreated]) = #" & Format(Date(),"mm/dd/yyyy") & "#"
 
I don't see the point of this . . .
Code:
"WHERE DateCreated = #" & Format(Date(),"mm/dd/yyyy") & "#"
The VBA.Date() function returns a date datatype. When you format it, you return a string. When you delimit that string with '#' you convert it back to a date--exactly the same as the VBA.Date() function--and nothing is changed. So this is the equivalent, which is much simpler, . . .
Code:
WHERE [DateCreated] = Date()"
. . . or am I missing something?
Thanks,
 

Users who are viewing this thread

Back
Top Bottom