Dlookup

D

Dan

Hi:

Here is my code that works just for the first User Id and
psw; does not check/work for the other records. Any HELP
is appreciated

Thanks,

Dan

Option Compare Database

Private Sub OK_Click()
Dim eof
If (DLookup("password", "PWTbl")) = Me.pw Then
If (DLookup("userid", "PWTbl")) = Me.UI Then

DoCmd.Close
stDocName = "mainmenu"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
MsgBox "Incorrect Password"

End If

End If

End Sub
 
T

Ted Allen

Hi Dan,

You have not entered any criteria to restrict the domain
on your DLookups, so they will just find the values of
the specified field in the first record. The optional
third argument of Dlookup is the domain restriction. If
you know that each user has only one entry in the
Passwords table, you should be able to get what you are
looking for by using (watch the wrapping):

If DLookup("password", "PWTbl", "userid = " & Me.UI) =
Me.pw Then

This assumes a numeric UserID. If userid is text you
would need to use:

If DLookup("password", "PWTbl", "userid = '" & Me.UI
& "'") = Me.pw Then

If the user could have multiple entries, you would need
to add an AND condition to the criteria to specify that
password = Me.pw, such as:

If DLookup("password", "PWTbl", "userid = " & Me.UI & "
AND password = " & Me.pw) = Me.pw Then

Again though, if password is text (which it likely is)
you would need to modify to surround it with single
quotes.

Generally most of us try to avoid using Dlookup as much
as possible because it can be slow. But, in this case
the time will likely still be short enough that it may be
fine.

But, if it does seem to be slow and you want to look at
other ways to do it you could consider constructing a sql
statement (by concatenating a string) that would select
the records matching the userid and password and then
check the recordset's record count (either 1 or 0) to see
if a matching entry exists. I'm sure there are other
ways to check as well.

HTH, Ted Allen
 

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