Need help with the following simple problem

G

Guest

Hellow

I have a copy of Access 2000 and I’m trying to learn access from a book
titled “Access2000 Programming Blue book.

In the following code the Dlookup always return “Rosebudâ€, and “Kane†in
variables Qresult1 and qresult2 respectively. This gives the desired
result that the author is looking for but I don’t understand why these
lookups always return “Rosebud†and “Kane†no matter what I request. It’s
as if these were the only values in the table. What’s going on?

Thanks Glo


Option Compare Database

Sub Logon()
'Variable declaration section
Dim Username
Dim Password
Dim Qresult1
Dim qresult2


'Variable definition section
Username = InputBox( _
"You're programming with Access 2000." & Chr(13) & Chr(13) & _
"Please enter your username.")


Password = InputBox( _
"You're doing a great job!" & Chr(13) & Chr(13) & _
"Now, please enter your password")
'Query execution section

Qresult1 = DLookup("[Username]", "FirstTable", "[Username] = username")
qresult2 = DLookup("[Password]", "FirstTable", "[Password] = password")


'Processing logic section
If Username = Qresult1 And Password = qresult2 Then
MsgBox "Congratulations, Give this man a cigar!"
Else
MsgBox "Hey! That's not right!" & Chr(13) & "No cigar for you!"
End If
End Sub


The tables are as follows:
Username Password FirstEmployeesID
Bruce Batman 30
Shaft JohnShaft 32
Rosebud Kane 22
Fox Mulder
Spiderman Spidey 31
Clark Superman


Fieldname Data type
Username Text
Password Text
FirstEmployeeID number
 
V

Van T. Dinh

I don't have this book but the syntax of the DLookUp is wrong and the logic
used in the code is incorrect. Basically, with the posted code, someone
enters a correct username and a password that matches one of the passwords
in the table, _not_ necessarily the password corresponding to the entered
username, will get through.

Is the posted code a true copy of the code in the book? If it is, ditch the
book and learn effectively from better Access books you can find in the
bookshop.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top