Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Field Search 1

Status
Not open for further replies.

PONGY

Technical User
Mar 16, 2009
2
CA
I want to code a date search when my access 2003 form loads. The code will search for the first date in a series of records that matches the current date. The search field in the database is 'Date'. Even though the formatting of 'Date' and 'Now' appears the same I do not find a match. 'Date' is formatted to medium date in my table.

Dim Mydate As Date
Mydate = Format(Now(), mediumdate)
DoCmd.GoToRecord , , acFirst
STARTDateCHK:
If Mydate = [Date] Then
GoTo Done
End If
DoCmd.GoToRecord , , acNext
GoTo STARTDateCHK
Done:
End Sub

 



Hi,

The "formatting" has nothing to do with the actual value of a date.

Even though the formatting of 'Date' and 'Now' appears the same I do not find a match.

Thats because Date is ONLY the INTEGER portion, and Now contains BOTH the INTEGER part and the FRACTIONAL part, which is Time.

So the only time that Date() = Now() is at 12:00 AM.

Also, Format returns a STRING and not a Date.

Also, Date is a reserve word and ought not to be used as a field name.
Code:
    If Date() = Int([YourDateField]) Then
      GoTo Done
    End If




Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Thanks so much for quick reply.Will correct.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top