Compare two text boxes on the same form before moving to next form...

I am setting up a simple database to capture e-mail addresses for a customer.  I want the customer to enter his/her email address two separate times and compare the text data before moving to the next form to make sure the e-mail address is accurate.  What is the simplest way to accomplish this?

Thanks!
mstefaniAsked:
Who is Participating?
 
Kelvin SparksConnect With a Mentor Commented:
OK, bind the second in the tab order.
 Now try this
Use the BEFORE update to run
If (me.email1<>Me.email2 then
   Msgbox "The email addresses you entered do no match. Please try again.",vbOKOnly+vbInformation,"mail addresses do not match"
    Cancel = true
   Me.email1 = ""
   Me.email2 = ""
   Me.email1.Setfocus
End if
 
Kelvin
 
0
 
Kelvin SparksCommented:
On the after update event of the 2nd text box use
 
If me.text1<>Me.text2 then
   Do something......
End if
 
Kelvin
0
 
mstefaniAuthor Commented:
Thank you for the quick response.  I am using code builder to complete.  If the two are the same I want it to move onto the next field, other wise give an error message.  Any thoughts?

The two text boxes are calle email1 and email2

Thanks Again!
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Jerry MillerCommented:
If me.email1 = me.email2 then

me.NextField.SetFocus

else

MsgBox("your error message")

end if
0
 
Kelvin SparksCommented:
If the next field is after email2 my code would work fine BUT a few other issues .
If me.email1<>Me.email2 then
  Do something......
End if
1st are either of the two email fields bound to data fields? WE probably need to intercept before we get to the after update, clean out the two and make them start again if not matching.
 
Please advise
 
Kelvin
0
 
mstefaniAuthor Commented:
Yes, both fields are bound to data fields.  It would be nice to clear both fields and start over, also, if it works better, I can have the first bound to a data field and the second bound to just a text field for doing the comparison.  I need only capture the e-mail address once.
0
 
mstefaniAuthor Commented:
kelvinsparks,

Thanks for this information.  I have put code into the form like you suggested, but when I tested it, it moved right on to the next record without noticing the two email addresses were not the same.  Not sure what I am doing wrong.  I bind the second text box in the tab order.  I did have to remove the "(" in the first line of code.  Any other suggestions as to what I might be doing wrong?
0
 
Kelvin SparksCommented:
Check that the Me.names are those of the controls not data field names.
 
Do you know how to step through the code. If so, put a breakpoint on the IF statement line and check what values you were getting for email1 and 2. Also, on hindsight, it may be better on the AFTER update event.
 
Kelvin
0
 
mstefaniAuthor Commented:
Kelvin,

So I shut down access and reopened it, and it is partially working.  When I type in the email addresses, now the message coems up, but after that, the system wants to debug the program.

Microsoft Visual Basic

Run-time error '-2147352567 (80020009)

The macro or function set to the BeforeUpdate  or ValidationRule for the field is preventing Microsoft Office Access from saving the data in the field.

When I click debug, it takes me to the code and the portion " Me.email2 = "" is in yellow.

Any thoughts?
0
 
mstefaniAuthor Commented:
Kelvin

As long as the email name match, there is no problem.

I am not to sure how to step through the code...

Thanks!
0
 
mstefaniAuthor Commented:
Kelvin,

Right now the second email text box does not have a control source.  If I enter Email2, then an "!" shows up next to the text box saying...

Invalid Control Property:Control Source
No such field in the field list

Perhaps I should have the second email in the table anyway?

Thoughts?
0
 
Kelvin SparksCommented:
I'd like 2nd to have the email address controlsource as the field you'd like the email address saved in. Delete anything for the control source of the 1st, so that it is "unbound".
 
When you look at the code you've created, if you click in the margin to the left of the line you'll get a brown dot and the line will be highlighted. This is a breakpoint. Close out of the code and try the form. If the form passes that part of code, it'll stop and throuw you into the code so you can see what is happening. Pressing F8 will move it line by line. After moving on 1 line if you put the cursor over the me.email1 and 2 it will give you the values that it has for each.
0
 
Kelvin SparksCommented:
Run-time error '-2147352567 (80020009)

The macro or function set to the BeforeUpdate  or ValidationRule for the field is preventing Microsoft Office Access from saving the data in the field.


Change the code to AFTER update to get rid of this
0
 
mstefaniAuthor Commented:
OK... I'll keep you posted.  Thanks for all the help with this.  How much longer are you going to be online?
0
 
Kelvin SparksCommented:
Its Friday night here, and I work from home. Am wandering to and fro from computer. Will be watching for a few hours yet (but the beer may cloud judgement!)
 
Kelvin
0
 
mstefaniAuthor Commented:
OK... I think I thoroughly messed up the previous database, so I am going to start from scratch... Should take about 10 minutes or so...
0
 
mstefaniAuthor Commented:
Success!  After recreating the database, everything worked Great!  Have a Great Evening!

Kevin
0
 
Kelvin SparksCommented:
Here a quick db with the code working
Kelvin
0
 
Kelvin SparksCommented:
Help if I uploaded the db
Email.mdb
0
 
mstefaniAuthor Commented:
He was great and patient.
0
 
Kelvin SparksCommented:
Cheers, glad to hear it worked!!
 
Kelvin
0
All Courses

From novice to tech pro — start learning today.