OldValue and case-sensitivity

I need to prevent editing of a field after the record has been saved.  The analyst wishes to accomplish this by doing a check when the record is saved, and then display a message.

So, I did this:

   If Not frmMe.NewRecord Then
    If (TStr(frmMe!txtTestId.OldValue) <> TStr(frmMe!txtTestId)) Then
        Msg_Err GetStringConst("Test", 280)
        Cancel = True
        GoTo ExitRoutine
    End If
   End If

Open in new window

The problem is, this check does not recognize that the value is different if you simply change the case of the value.

In other words, if txtTestId.OldValue is "DEF", and I change the value of txtTestId to "def", the two values are interpreted as equal, so the message does not display.

How do I make this check case-sensitive?

Who is Participating?
Dale FyeConnect With a Mentor Commented:
Checkout the strComp() function in Access Help
Rey Obrero (Capricorn1)Commented:
here is one quick way
in the top of your Form module, use

Option Compare Binary
Go sideways!
Lock that control if you are not on a new record

If Not frmMe.NewRecord Then
    frmMe!txtTestId.locked = true
    frmMe!txtTestId.locked = false
end if

Then nobody can change it if you aren't on a new record
L_MalchiodiAuthor Commented:
Thanks, StrComp worked nicely.  I changed the line where the check is done to this:

If StrComp(TStr(frmMe!txtTestId), TStr(frmMe!txtTestId.OldValue), 0) <> 0 Then
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.