I am new to VBA (Access), and I'm trying write a proceedure to verify Phone field values for a particular City. Example: if the City is Cleveland, the two 'valid' area codes are 216 and 440.
I am using the VBA statement below, and the message block is popping up even when the first three numbers meet the 216 or 440 criteria. Can anyone help me identify how to correct?
I am using the VBA statement below, and the message block is popping up even when the first three numbers meet the 216 or 440 criteria. Can anyone help me identify how to correct?
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer) Dim PhoneFirstThree As Integer If Not IsNull([City]) And Not IsNull([Phone]) Then PhoneFirstThree = Val(Left([Phone], 3)) Select Case [City] Case "Cleveland" If PhoneFirstThree <> 216 Or PhoneFirstThree <> 440 Then DoCmd.CancelEvent MsgBox "Cleveland phone numbers must start with 216 or 440" Me.Undo [Phone].SetFocus End If End Select End If End Sub
Comment