compare characters in two different fields

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top