My VB coding is terrible! Please help

morlan

Registered User.
Local time
Today, 21:22
Joined
Apr 23, 2003
Messages
143
I made the following code to validate dates entered in a text box.
The code works fine in Access XP but doesn't work in Access 97, 2000.

I have put in down to my bad coding techniques!

Here is the code I have used. Can somebody knock me into shape?


Private Sub txtDispDate_AfterUpdate()

' Check that the date entered is not more than 2 weeks old


If CDate(Me.txtDispDate.Value) + 14 < Me.txtDateTimeKeyed.Value Then
MsgBox "This application is over 2 weeks old. Please ensure that you have entered the correct date. ", vbCritical, "Validation"

Me.txtAppDate.SetFocus
Me.txtDispDate.SetFocus

Exit Sub

End If


' Check that the date entered is not greater that todays date


If Me.txtDispDate.Value >= Me.txtDateTimeKeyed.Value Then

MsgBox "The dispatch date your entered is greater than todays date. Please confirm your entry before you continue.", vbQuestion, "Validation"

Me.txtAppDate.SetFocus
Me.txtDispDate.SetFocus

Exit Sub

End If

' Check that the date entered is not less than txtAppDate value


If Me.DispDate.Value < Me.txtAppDate.Value Then

MsgBox "The dispatch date cannot be before the application date.", vbCritical, "Validation"

Me.txtAppDate.SetFocus
Me.txtDispDate.SetFocus

Exit Sub

End If

Me.chkLockDispDate.Value = True
Me.txtCustName.SetFocus

End Sub
 
It would be nice to know what doesnt work?

Regards
 
You should use the Before Update event.
 
No errors, but then whats wrong? Get the wrong message? when?

Regards

P.S. i notice that your only using CDate once, might that be the source of your problems?
 

Users who are viewing this thread

Back
Top Bottom