Eljefegeneo
Still trying to learn
- Local time
- Today, 02:30
- Joined
- Jan 10, 2011
- Messages
- 902
I do have a solution to my problem but I do not understand why my first attempt did not work. I want to make sure that a user does not type in a "." all by itself (a habit picked up from a long used DOS based DB). So I tried the following:
Private Sub ADDRESS1_BeforeUpdate(Cancel As Integer)
If ADDRESS1 = "." Then
If MsgBox("Do Not Type a '.' in this field without any other text", vbOKOnly) = vbOK Then
ADDRESS1 = ""
Me.CITY.SetFocus
End If
End If
End Sub
But I got the following error:
Run Time Error '-2147352567 (800200009)';
The macro or function set to the Before Update or Validation rule is preventing MS access from saving the data in the field.
So after trying numerous alternatives on the BeforeUpdate event, I used the following:
Private Sub ADDRESS1_AfterUpdate()
If ADDRESS1 = "." Then
If MsgBox("Do Not Type a '.' in this field without any other text", vbOKOnly) = vbOK Then
ADDRESS1 = ""
End If
End If
End Sub
It does exactly what I wanted it to do. Remind the user not to type in a sole "." and set the focus to the next control, which is [City}.
I have always thought that one tested for data validation in the Before Update event. But I cannot figure out how to correct the code in the Before Update event to (1) remind the user as to the error, (2) clear the field, and then set the focus to the next control in the tab order.
Private Sub ADDRESS1_BeforeUpdate(Cancel As Integer)
If ADDRESS1 = "." Then
If MsgBox("Do Not Type a '.' in this field without any other text", vbOKOnly) = vbOK Then
ADDRESS1 = ""
Me.CITY.SetFocus
End If
End If
End Sub
But I got the following error:
Run Time Error '-2147352567 (800200009)';
The macro or function set to the Before Update or Validation rule is preventing MS access from saving the data in the field.
So after trying numerous alternatives on the BeforeUpdate event, I used the following:
Private Sub ADDRESS1_AfterUpdate()
If ADDRESS1 = "." Then
If MsgBox("Do Not Type a '.' in this field without any other text", vbOKOnly) = vbOK Then
ADDRESS1 = ""
End If
End If
End Sub
It does exactly what I wanted it to do. Remind the user not to type in a sole "." and set the focus to the next control, which is [City}.
I have always thought that one tested for data validation in the Before Update event. But I cannot figure out how to correct the code in the Before Update event to (1) remind the user as to the error, (2) clear the field, and then set the focus to the next control in the tab order.