Date Range problems

G

Guest

Hi,

I have a form with two textboxes for entering a date range. When the user
clicks OK on the form, i validate that the texboxes are dates... this works
fine... then I want to check that the from date is not greater than the to
date, but it is not working consitently. My message is returning that my from
date is greater that my to date even when it isn't. sample code:

If Not IsDate(tbxFrom_Date.Value) Then
MsgBox "The value entered in the From Date field is not a valid Date"
tbxFrom_Date.SetFocus
ElseIf Not IsDate(tbxTo_Date.Value) Then
MsgBox "The value entered in the To Date field is not a valid Date"
tbxTo_Date.SetFocus
ElseIf tbxFrom_Date > tbxTo_Date Then
MsgBox "The From Date is greater than the To Date. Please change. "
& _
tbxFrom_Date.Value & " - " & tbxTo_Date.Value
tbxFrom_Date.SetFocus
tbxFrom_Date.Value = ""
Else
'MsgBox "all good"
Unload Me
End If

when I read at my resulting message, the from date is definitely less than
the to date...

ideas?
 
G

Guest

I figured it out... I changed the one line:
from:
ElseIf tbxFrom_Date > tbxTo_Date Then
to:
ElseIf DateValue(tbxFrom_Date.Value) > DateValue(tbxTo_Date.Value) Then
 

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