date comparison

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I cannot find any mention of this issue.

Its probably me, but I can't figure it out. I wish to compare dates and
return a message sometimes. Seems simple enough, not gettin' it. See code.

If Me.txtStartDate < Me.txtEndDate Then
response = MsgBox(msg, style, title)
End If

txtStartDate and txtEndDate are formatted m/d/yy, exist on the form, but
when I run the code I get nothing. Example: [StartDate]= 3/1/07 and
[EndDate]=3/15/07 will not return the message.

I know that dates/times are not the same as plain integer, but what am I
doing wrong...the help isn't much help.

As usual, any help is very much appreciated.
 
You could set a validation rule in the table or in the form of the
field/control EndDate with validation text saying what you want if the rule
has been broken.
 
Try converting the text box to dates

If CVDate(Me.txtStartDate) < CVDate(Me.txtEndDate) Then
response = MsgBox(msg, style, title)
End If
 
Thanks for responding. It still won't work.

I should have said I am testing the date entered [txtAddDate] against the
range of [txtStartDate] thru [txtEndDate] to give the message if the entered
date is outside that range. I know I wasn't clear; I was using the code to
find why it wouldn't work. Does this provide a clue?

--
Thanks for your help,
Chris


RobUCSD said:
You could set a validation rule in the table or in the form of the
field/control EndDate with validation text saying what you want if the rule
has been broken.


Chris said:
I cannot find any mention of this issue.

Its probably me, but I can't figure it out. I wish to compare dates and
return a message sometimes. Seems simple enough, not gettin' it. See code.

If Me.txtStartDate < Me.txtEndDate Then
response = MsgBox(msg, style, title)
End If

txtStartDate and txtEndDate are formatted m/d/yy, exist on the form, but
when I run the code I get nothing. Example: [StartDate]= 3/1/07 and
[EndDate]=3/15/07 will not return the message.

I know that dates/times are not the same as plain integer, but what am I
doing wrong...the help isn't much help.

As usual, any help is very much appreciated.
 
Thanks. Tried that and no joy.

Please see my post to RobUCSD for more information. I admit I didn't give
you guys enough.
--
Thanks for your help,
Chris


Ofer Cohen said:
Try converting the text box to dates

If CVDate(Me.txtStartDate) < CVDate(Me.txtEndDate) Then
response = MsgBox(msg, style, title)
End If

--
Good Luck
BS"D


Chris said:
I cannot find any mention of this issue.

Its probably me, but I can't figure it out. I wish to compare dates and
return a message sometimes. Seems simple enough, not gettin' it. See code.

If Me.txtStartDate < Me.txtEndDate Then
response = MsgBox(msg, style, title)
End If

txtStartDate and txtEndDate are formatted m/d/yy, exist on the form, but
when I run the code I get nothing. Example: [StartDate]= 3/1/07 and
[EndDate]=3/15/07 will not return the message.

I know that dates/times are not the same as plain integer, but what am I
doing wrong...the help isn't much help.

As usual, any help is very much appreciated.
 
Thanks, unhinged. I am familiar with it, have used it. I don't see how that
applies to testing outside a date range. Am I missing something?
 
If you want to check the date within a range of dates try

If CVDate(Me.txtAddDate) < CVDate(Me.txtStartDate) Or CVDate(Me.txtAddDate)
CVDate(Me.txtEndDate) Then
response = MsgBox(msg, style, title)
End If


Note: make sure that the If statement (until the then) will be in one line
 
Thanks again, Ofer...

I have been trying this in before and after update event. Nothing works. On
a lark I moved it to the exit event. Works!

Don't know why. Can you shed light? I am just referring to the text box
without the CVDate.
 
Back
Top