date comparisons (1 Viewer)

e2cheng

Registered User.
Local time
Today, 05:42
Joined
Dec 13, 2002
Messages
72
Code:
if (txtDate) > Date then
   msgbox "Date too big"
end if

i'm putting in "09/04/01" and I'm still getting the 'date too big' msg. any clues?? my comp date is set properly, but i was wondering if that function only checks the day field date+month field and leave out the year..

thanks in advance for any tips!
 

ColinEssex

Old registered user
Local time
Today, 09:42
Joined
Feb 22, 2002
Messages
9,129
Where have you got this bit of code?

Col
:cool:
 

e2cheng

Registered User.
Local time
Today, 05:42
Joined
Dec 13, 2002
Messages
72
Thank you for your rep Col,

part of a subroutine that checks for a valid date before being used to generate an SQL statement. there's a whole bunch of stuff around it, but i just isolated the particular case that's giving me issues.

Thank again,
Eric
 

ColinEssex

Old registered user
Local time
Today, 09:42
Joined
Feb 22, 2002
Messages
9,129
If its on a form then try this....

If Me.TxtDate > Date Then

MsgBox "Date too big"

End If

Col
:cool:
 

e2cheng

Registered User.
Local time
Today, 05:42
Joined
Dec 13, 2002
Messages
72
yep, sorry, it's on a form...

but yeah i just tried inserting me. into it. still doesn't work...
 

ColinEssex

Old registered user
Local time
Today, 09:42
Joined
Feb 22, 2002
Messages
9,129
Its strange - The code I suggested does work. Have you tried it in the AfterUpdate event of the txtDate box?

Col
:cool:
 

e2cheng

Registered User.
Local time
Today, 05:42
Joined
Dec 13, 2002
Messages
72
just tried that.. same thing.. something is seriously wrong, i was using it the other day and it never gave that msg...
 

Ally

Registered User.
Local time
Today, 09:42
Joined
Sep 18, 2001
Messages
617
I've got very similar code that works, so can't understand why yours isn't. Are you able to post anything here that we can have a look at.
 

neileg

AWF VIP
Local time
Today, 09:42
Joined
Dec 4, 2002
Messages
5,975
Code works fine for me. You haven't changed the regional setting for dates on the machine, have you? I've have found that changing the PC setting from non-US to US format (or vice versa) can cause various date problems, even thought Access should adjust itself.
 

e2cheng

Registered User.
Local time
Today, 05:42
Joined
Dec 13, 2002
Messages
72
thank you very much for the replies.. the code is as follows:

Code:
dim mydate as date
mydate = date

If IsNull(txtBeginDate) Or IsDate(txtBeginDate) = False _
   Or txtBeginDate > myDate Then
     MsgBox "Enter a valid beginning date.  Try again."               End If
If (Not (IsNull(txtEndDate)) And IsDate(txtEndDate) = False) _ 
   Or txtEndDate > myDate Or txtEndDate < txtBeginDate Then
      MsgBox "Enter a valid ending date.  Try again."
End If

this really boggles me. for the second if statement, if i move the last case (txtendDate <txtbegindate) into a separate if statement, then it runs thorugh without problem. but it won't perform the last if qualifying statement properly. ie. i can enter a date prior to the first date and it won't pick up on it.

thank you for your help!
 

neileg

AWF VIP
Local time
Today, 09:42
Joined
Dec 4, 2002
Messages
5,975
You set your variable as:
mydate = date

You refer to it as
txtEndDate > myDate

mydate and myDate are different because you have capitalised the D
 

e2cheng

Registered User.
Local time
Today, 05:42
Joined
Dec 13, 2002
Messages
72
thanks for the reply...

sorry, my bad..

i typed it wrong in the previous message, it's actually capped in the code..

have no idea what up...
 

Users who are viewing this thread

Top Bottom