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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date fields and VBA

Status
Not open for further replies.

sogibear

Programmer
Jul 4, 2002
45
GB
Hello,

I'm using the code below to perform a validation check on a field. unfortunately i keep getting an error13 message that says 'There seems to be a problem with your date'

Any suggestiong ?

Thanks

******** CODE ******************
'DOB must not be greater than today
If CDate("#&Me.txtDOB&#") > Date Then
MsgBox "Please re-enter Date of Birth", vbExclamation
ValidateFormData = False
GoTo Exit_ValidateFormData
End If
 
Try changing

If CDate("#&Me.txtDOB&#") > Date Then

to

If CDate(Me.txtDOB) > Date Then

There are two ways to write error-free programs; only the third one works.
 
Sorry,
the error message i get is "Type Mismatch"
 
re-write it like this:

If CDate(Me.txtDOB) > Date Then
MsgBox "Please re-enter Date of Birth", vbExclamation
ValidateFormData = False
GoTo Exit_ValidateFormData
End If
 
CDate(Me.txtDOB) was the first thing i tried guys, it still doesn't work.

:-(
 
What exactly are you putting in me.txtDOB?
There are two ways to write error-free programs; only the third one works.
 
I've just put a textbox on a form (txtDate) with the input mask

99/99/00;0;_

and the following code works as you would expect..

Private Sub txtDate_AfterUpdate()

If CDate(txtDate) > Date Then
MsgBox "Greater"
Else
MsgBox "Less"
End If

End Sub

There are two ways to write error-free programs; only the third one works.
 
Maybe you should rewrite your routine like this:


If Isdate(Me.txtDOB) then
If CDate(Me.txtDOB) > Date Then
MsgBox "Please re-enter Date of Birth", vbExclamation
ValidateFormData = False
GoTo Exit_ValidateFormData
End If
Else
MsgBox("Invalid Date")
ValidateFormData = False
GoTo Exit_ValidateFormData
end if
 
Thanks guy's for all your help, i finally figured it out. All what you sugested was right except all the time i was concerned about the date being in the future in my validation check, i forgot to check to see in the value was a null or zero length string !!

DOH !!!

allanon, i just read your last reply using isDate() which would probably solved it for me.

Programming aye ? Sometimes you love it, sometimes its enough to drive a man insane !! Arrrghhhh !

:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top