By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,106 Members | 2,679 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,106 IT Pros & Developers. It's quick & easy.

compare values entered into text boxes with fields in table

P: 8
hi:
i want to compare the values that entered into text boxes with fields in table
if it exists in the table i want to open page called (result)
else open(voting)
but when i run the program my code in two cases open the result page
here is my code
Expand|Select|Wrap|Line Numbers
  1. If Me.f2.Value = DLookup("Passwords", _
  2.       "Passwords", _
  3.       "[Names]='" & Me.f1.Value & "'") Then
  4.    '
  5.    DoCmd.Close acForm, "Main form", acSaveNo
  6.    DoCmd.OpenForm "result"
  7. ElseIf Me.f2.Value <> DLookup("Passwords", _
  8.       "Passwords", _
  9.       "[Names]='" & Me.f1.Value & "'") Then
  10.    '
  11.    DoCmd.Close acForm, "Main form", acSaveNo
  12.    DoCmd.OpenForm "Voting"
  13. End If
  14.  
Mar 8 '13 #1
Share this Question
Share on Google+
7 Replies


Seth Schrock
Expert 2.5K+
P: 2,941
Please read Use a good thread title

I think you have a slight misunderstanding of how the If/Then/Else statement works. You don't need to test for the Me.f2 <> Dlookup... as that would be the same as the false of Me.f2 = Dlookup... so the Else portion of the code would run. Try the following
Expand|Select|Wrap|Line Numbers
  1. If Me.f2.Value = DLookup("Passwords", "Passwords", "[Names]='" & Me.f1.Value & "'") Then
  2.     DoCmd.OpenForm "result"
  3. Else
  4.     DoCmd.OpenForm "Voting"
  5. End If
  6.  
  7. DoCmd.Close acForm, "Main form", acSaveNo
Mar 8 '13 #2

P: 8
thanks for your answer
but also when i use this code
in two cases it open the result page
Mar 8 '13 #3

Seth Schrock
Expert 2.5K+
P: 2,941
Expand|Select|Wrap|Line Numbers
  1. Dim strPassword as String
  2. strPassword = DLookup("Passwords", "Passwords", "[Names]='" & Me.f1.Value & "'")
  3.  
  4. Debug.Print strPassword
  5. Debug.Print Me.f2
  6.  
  7. Stop
  8. If Me.f2.Value = strPassword Then
  9.     DoCmd.OpenForm "result"
  10. Else
  11.     DoCmd.OpenForm "Voting"
  12. End If
  13.  
  14. DoCmd.Close acForm, "Main form", acSaveNo
Try the above code. Execution will stop on line 7. Check the values in the immediate window (Ctrl + G opens it). Now press F8 to step through the code one line at a time. Tell me if the values in the immediate window are equal or not and then which lines of code were executed going through the If/Then/Else statement.
Mar 8 '13 #4

P: 8
the values in the immediate window are equal
and the lines 8 9 12 14 are executed
Mar 8 '13 #5

Seth Schrock
Expert 2.5K+
P: 2,941
Those are the results that I would expect. Now try it with the wrong password. I assume this is where you are having the problem?
Mar 8 '13 #6

P: 8
the value not in the table but it appear equal in the immediate window and take the same steps to the result page
Mar 8 '13 #7

Seth Schrock
Expert 2.5K+
P: 2,941
Normally I would ask what the values in the immediate window are, but since they are passwords, I'll let you do the checking.

You type in a wrong password (X)
The script runs and it gives you what the correct password is (Y) and what it sees in your password textbox (Z)

Are X and Z equal, and Y and Z not equal?
Mar 8 '13 #8

Post your reply

Sign in to post your reply or Sign up for a free account.