Jonathan Snyder via AccessMonster.com said:
Dirk,
Thanks for the suggestion, but it did not work. If the data entered
does not meet the validation code, I want to cancel the update event
and clear the invalid data from the field. I can cancel the event to
suppress the default data valadation message, but I am unable to
clear the invalid data, i guess because the field required property
is set to yes.. here is my code, any other suggestions.
thanks
Private Sub Trip_ID_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_Trip_ID_BeforeUpdate
Dim trip As String
Dim vill As String
Dim strvill As String
Dim strtrip As String
vill = Me.Village
strvill = Left(vill, 1)
trip = Me.Trip_ID
strtrip = Left(trip, 1)
If strtrip <> strvill Then
MsgBox "Your Trip ID must begin with the first letter of the
village name", vbOKOnly, "Hey Dude"
Cancel = True
Me!Trip_ID.Undo
Hmm, I can't make it undo itself under those circumstances, either.
There may be a way, but I can't find it. Unless you want to remove the
Required setting for the field and rely on your form's BeforeUpdate
event to validate it, it seems to me your best bet would be to validate
this field as it is being entered, in its Change event. I normally
never use that event, but in this case it might be appropriate:
'----- start of example code -----
Private Sub Trip_ID_Change()
Dim strVill As String
strVill = Left(Me.Village, 1) & vbNullString
If Len(strVill) > 0 Then
With Me!Trip_ID
If Len(.Text) > 0 Then
If Left(.Text, 1) <> strVill Then
MsgBox _
"Your Trip ID must begin with the first letter "
& _
"of the village name", _
vbOKOnly, _
"Hey Dude"
.Undo
End If
End If
End With
End If
End Sub
'----- end of example code -----
..