Format function in Ms Access 97

  • Thread starter chetna k via AccessMonster.com
  • Start date
C

chetna k via AccessMonster.com

I am in trouble in comparing two dates:

as I wrote code as

If (Format(Me![Delivery Timescales], "short date") < Format(Now(), "short
date")) Then
MsgBox "Please enter Requested Start date as current date
or any future date", vbCritical
End If

where [Delivery Timescales] is a Text Box and the whole code has been written
on the click of a button.

The Error I am getting is the If condition is coming false as I entered
31/12/2004 in [Delivery Timescales] text box.

Can anybody help?

Thanks in advance.
 
A

Allen Browne

Drop the Format() part. Access knows how to compare two dates. You are
forcing it to perform a *string* comparision rather than a date comparison
when you use the Format() function.

Since your dates as d/m/y, take a look at this article:
International Date Formats in Access
at:
http://allenbrowne.com/ser-36.html
It explains how to ensure Access always understands your dates correctly.
 
C

chetna k via AccessMonster.com

Thanks for your help.

I used now CDATE function to compare dates and it is working fine.

Thanks
Chetna

chetna said:
I am in trouble in comparing two dates:

as I wrote code as

If (Format(Me![Delivery Timescales], "short date") < Format(Now(), "short
date")) Then
MsgBox "Please enter Requested Start date as current date
or any future date", vbCritical
End If

where [Delivery Timescales] is a Text Box and the whole code has been written
on the click of a button.

The Error I am getting is the If condition is coming false as I entered
31/12/2004 in [Delivery Timescales] text box.

Can anybody help?

Thanks in advance.
 

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