Compare Text Boxes

Wes28

Registered User.
Local time
Today, 16:50
Joined
Dec 4, 2009
Messages
60
Trying to compare 2 text boxs on a form and see if there value's are equal. If they are, clear the value in the one field. If there not equal, display message that values don't match.

What I've tried so far



Code:
 If Me.txtSe.Value <> Me.ReSNum.Value Then
         Me.txtSe = ""
    Else
        MsgBox "Values Don't Match", vbCritical, "Search Error"
        'Me.txtSe = ""
    End If
 
In which event are you performing the check? You wouldn't want to perform it in either controls after update event so I would think the logical place to check would be in the forms before update event.

The logic in your code is also out. Try:-

Code:
If Me.txtSe = Me.ReSNum Then
Me.txtSe Is Null
Else
MsgBox "Values Don't Match", vbCritical, "Search Error"
End If
 
Thanks db,

Was trying to do the check from a Command Button click.

I tried what you posted

If Me.txtSe = Me.ReSNum Then
Me.txtSe Is Null <--- Getting a Syntax Error on this line.
Else
MsgBox "Values Don't Match", vbCritical, "Search Error"
End If
 
Try = Null rather than Is Null.

I wouldn't put this behind a command button (unless its a custom save button) as this relies on the user to click the button which is not something you want to be doing...
 
Ok. I tried what you said.. No error now.

But.. Trying to figure out why it's skipping the then statement.

Stepping through the code it jumps to the else command no matter what I put in the text boxes. Even if there equal to one another or not equal..

Almost like it doesn't see the then statement. Just for the fun of it I changed the equal back to <>. The code then does the exact oposite. It wont go to the else statement no matter if the values are equal or not..

Gotta be something simple.
 
Are the text boxes bound and, if so, are they the same exact datatypes? Also if there is any formatting on the text boxes (in the format property) are they formatted exactly the same?
 
Oh, and also if they are bound fields, then putting something in there isn't going to change the value of it until the record gets updated.
 
ok txtSe is an Unbound text box. And ReSNum is a bound text box with a Number Format.

Only wanting to see if there value is the same after the command button is clicked. So what I have here will not work?
 
You should be able to check, but make sure that the txtSE is formatted the same as the other field. But it could be that you have rounding issues going on with ReSNum and so it isn't quite the same even when you type in what appears to be the same thing into txtSE. What number type did you use for ReSNum?
 
Ok the Format on the form property for both text boxes is empty. But the bound text box ReSNum in the table is set as a number.


Should I change the Format porperty on both to a General Number?
 
I changed the Format on both Text boxes to General Number Format..

Works like a charm now..

Thanks for your help guys.
 
What data type are you using for ReSNum in the table? That would be what is under FIELD SIZE in the field's properties in the table.

Normally I do not use formatting at the table level. For one it can make for problems up the line, and second it doesn't really flow through to reports so you still need to format again. I format at the last place it is at where I need to see it.
 
Normally I do not use formatting at the table level. For one it can make for problems up the line, and second it doesn't really flow through to reports so you still need to format again. I format at the last place it is at where I need to see it.


Hmm. Didn't know that. Will keep this in mind.

Thanks,
 

Users who are viewing this thread

Back
Top Bottom