compare characters in two different fields

R

Ricoy-Chicago

I have a field named [ProgramCode] and a field named [ClassCode]. To minimize
typing errors, the first 3 letters of [ClassCode] must match the first 3
letters of the [ProgramCode]. Example:

ProgramCode ClassCode
MBS D MBS 10-10 This is a valid class code, first 3 char.
match
MBS D MAS 10-10 This is an invalid class code, first 3
char. don't match

[ProgramCode] is selected from a dropdown field, [ClassCode] has to be
typed, it is not a dropdown field because there are way too many class codes.

Thank you for your help.
 
S

Steve Schapel

Ricoy,

You could put code similar to the following, in the Before Update event
of the ClassCode textbox...

If Not IsNull(Me.ClassCode) Then
If Left(Me.ClassCode, 3) <> Left(Me.ProgramCode, 3) Then
MsgBox "Invalid Class Code"
Cancel = True
End If
End If
 
R

Ricoy-Chicago

That did it!

Thanx Steve (Sorry that I could not rate your answer, but there was no
button showed)

Steve Schapel said:
Ricoy,

You could put code similar to the following, in the Before Update event
of the ClassCode textbox...

If Not IsNull(Me.ClassCode) Then
If Left(Me.ClassCode, 3) <> Left(Me.ProgramCode, 3) Then
MsgBox "Invalid Class Code"
Cancel = True
End If
End If

--
Steve Schapel, Microsoft Access MVP


Ricoy-Chicago said:
I have a field named [ProgramCode] and a field named [ClassCode]. To minimize
typing errors, the first 3 letters of [ClassCode] must match the first 3
letters of the [ProgramCode]. Example:

ProgramCode ClassCode
MBS D MBS 10-10 This is a valid class code, first 3 char.
match
MBS D MAS 10-10 This is an invalid class code, first 3
char. don't match

[ProgramCode] is selected from a dropdown field, [ClassCode] has to be
typed, it is not a dropdown field because there are way too many class codes.

Thank you for your help.
 
Top