G
Guest
Let’s say there are a pair of date fields called ‘Printed’ and ‘Received’.
The idea is that when the user clicks the ‘Print’ form command, the current
date is entered into the former. When the form is circulated and returned to
the user, the user is expected to enter the date ‘Received’. So I decided to
create some error traps. Here’s my vba code
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
If Not IsNull(Me.Printed) And Not IsNull(Me.Received) Then
If (Printed >= Received) Then
Cancel = True
strMsg = "The dates were not entered correctly. "
End If
End If
If Cancel Then
strMsg = strMsg & "Complete the data or press <Esc> to undo your
entry." & vbCrLf
MsgBox strMsg, vbExclamation, "Invalid Data"
End If
End Sub
What I thought would happen when the user entered dates that were
implausible would be that on hitting “<Esc>â€, the data just entered would be
striken/removed from the control. That’s not what happens. Can someone show
me the error of my ways?
I don’t know if this bears mention, but when the user clicks the ‘Print’
button, the following pair of commands appear just after the one to print it
out:
Me.Printed = Date
Me.Received = ""
Thanks for any help in advance.
-Ted
The idea is that when the user clicks the ‘Print’ form command, the current
date is entered into the former. When the form is circulated and returned to
the user, the user is expected to enter the date ‘Received’. So I decided to
create some error traps. Here’s my vba code
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
If Not IsNull(Me.Printed) And Not IsNull(Me.Received) Then
If (Printed >= Received) Then
Cancel = True
strMsg = "The dates were not entered correctly. "
End If
End If
If Cancel Then
strMsg = strMsg & "Complete the data or press <Esc> to undo your
entry." & vbCrLf
MsgBox strMsg, vbExclamation, "Invalid Data"
End If
End Sub
What I thought would happen when the user entered dates that were
implausible would be that on hitting “<Esc>â€, the data just entered would be
striken/removed from the control. That’s not what happens. Can someone show
me the error of my ways?
I don’t know if this bears mention, but when the user clicks the ‘Print’
button, the following pair of commands appear just after the one to print it
out:
Me.Printed = Date
Me.Received = ""
Thanks for any help in advance.
-Ted