Solved

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

Posted on 2010-09-02
21
320 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
 
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

746 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now