Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2010-09-02
21
Medium Priority
?
340 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
  • 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
Technology Partners: 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 2000 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Suggested Courses

782 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