- Joined
- Feb 21, 2009
- Messages
- 1
- Reaction score
- 0
When I use the following code, I get a Runtime Error 2108:
Private Sub Phone_BeforeUpdate(Cancel As Integer)
'verify the first three digits of VA phones
Dim phFirstThree As Integer
If Not IsNull([State]) And Not IsNull([Phone]) Then
phFirstThree = Val(Left(Phone, 3))
Select Case State
Case "VA"
If phFirstThree <> 703 And phFirstThree <> 804 Then
DoCmd.CancelEvent
MsgBox "VA phone numbers must have an area code of 703 or 804"
Me.Undo
Phone.SetFocus
End If
End Select
End If
End Sub
However, If I remark out (or delete) the "Phone.SetFocus" line, the code works. Other people have tried my database using this code without problem.
Any ideas?
Private Sub Phone_BeforeUpdate(Cancel As Integer)
'verify the first three digits of VA phones
Dim phFirstThree As Integer
If Not IsNull([State]) And Not IsNull([Phone]) Then
phFirstThree = Val(Left(Phone, 3))
Select Case State
Case "VA"
If phFirstThree <> 703 And phFirstThree <> 804 Then
DoCmd.CancelEvent
MsgBox "VA phone numbers must have an area code of 703 or 804"
Me.Undo
Phone.SetFocus
End If
End Select
End If
End Sub
However, If I remark out (or delete) the "Phone.SetFocus" line, the code works. Other people have tried my database using this code without problem.
Any ideas?