Hello. I am trying to set up a before update event procedure to verify a
Canadian postal code with a certain format (A1A 1A1). I am a novice with Access and VBA, so bear with me.
Below is my code (EmployeePostalCode is the field name).
----------------------------------------------------------------
Private Sub EmployeePostalCode_BeforeUpdate(Cancel As Integer)
'Check format of EmployeePostalCode
Dim EmployeePostalCode As String
' Check format
If (UCase$(EmployeePostalCode) Like "[A-Z]#[A-Z] #[A-Z]#") Then _
Exit Sub
' If validation fails, display error message
EmployeePostalCode.SetFocus
MsgBox "Postal Code should have format A#A #A#."
End Sub
---------------------------------------------------------
It seems to work sparingly...What am I doing wrong here? I would appreciate any help I can get =0)
Canadian postal code with a certain format (A1A 1A1). I am a novice with Access and VBA, so bear with me.
Below is my code (EmployeePostalCode is the field name).
----------------------------------------------------------------
Private Sub EmployeePostalCode_BeforeUpdate(Cancel As Integer)
'Check format of EmployeePostalCode
Dim EmployeePostalCode As String
' Check format
If (UCase$(EmployeePostalCode) Like "[A-Z]#[A-Z] #[A-Z]#") Then _
Exit Sub
' If validation fails, display error message
EmployeePostalCode.SetFocus
MsgBox "Postal Code should have format A#A #A#."
End Sub
---------------------------------------------------------
It seems to work sparingly...What am I doing wrong here? I would appreciate any help I can get =0)