Solved

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

Posted on 2010-09-02
21
334 Views
Last Modified: 2012-05-10
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!
0
Comment
Question by:mstefani
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 10
21 Comments
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 33593557
On the after update event of the 2nd text box use
 
If me.text1<>Me.text2 then
   Do something......
End if
 
Kelvin
0
 

Author Comment

by:mstefani
ID: 33593604
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
 
LVL 18

Expert Comment

by:Jerry Miller
ID: 33593655
If me.email1 = me.email2 then

me.NextField.SetFocus

else

MsgBox("your error message")

end if
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 33593690
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
 

Author Comment

by:mstefani
ID: 33593715
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
 
LVL 22

Accepted Solution

by:
Kelvin Sparks earned 500 total points
ID: 33593751
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
 

Author Comment

by:mstefani
ID: 33594045
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
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 33594103
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
 

Author Comment

by:mstefani
ID: 33594109
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
 

Author Comment

by:mstefani
ID: 33594123
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
 

Author Comment

by:mstefani
ID: 33594143
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
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 33594165
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
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 33594172
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
 

Author Comment

by:mstefani
ID: 33594177
OK... I'll keep you posted.  Thanks for all the help with this.  How much longer are you going to be online?
0
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 33594215
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
 

Author Comment

by:mstefani
ID: 33594227
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
 

Author Comment

by:mstefani
ID: 33594291
Success!  After recreating the database, everything worked Great!  Have a Great Evening!

Kevin
0
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 33594292
Here a quick db with the code working
Kelvin
0
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 33594296
Help if I uploaded the db
Email.mdb
0
 

Author Closing Comment

by:mstefani
ID: 33594299
He was great and patient.
0
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 33594301
Cheers, glad to hear it worked!!
 
Kelvin
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question