DLookup multiple values

Clayhead

Registered User.
Local time
Today, 02:48
Joined
Jan 3, 2016
Messages
13
Hi I am still quite new to this. Looking for some help with a DLookup.

I am trying to build a password reset to my login screen as i am tired of changing passwords.

I am currently stuck on how to have a dlookup that checks a pin (me.EnterPin) against what pin is stored in table "Users" as well as making sure that the username (me.EnterExistingUsername) matches that records username.

For now i am just using 2 x MsgBox (Win/Fail) just to make sure it works.

What i have created below only returns fail. Please can someone help?

Code:
 If (IsNull(DLookup("[Username]", "Users", "[EnterExistingUsername] ='" & Me.EnterExistingUsername.Value & "' And PIN = '" & Me.EnterPin.Value & "'"))) Then
    MsgBox "Win"
    Else
    MsgBox "Fail"

Am i doing this all wrong?

Please help.
 
Not all wrong, in fact this method will work...

However, I think DCount would be a better method. With that you don't have to check for Null, you simply see if DCount()=1 (assuming Username is unique). 1=win, all else fail.

The problem with your criteria is that it expects [EnterExistingUserName] to be a field in Users. Is that correct? You have both [EnterExistingUserName] field and [Username]? Seems odd.
 
Thanks for getting to me. Not entirely sure how to use a dcount but i will look into it.

Yeah i thought it was strange also. Logic i am trying to use is.

Does Username match username in table Y/N
Does PIN match whats in the table Y/N
(both matching from form to table)

Win/Fail

[EnterExistingUsername] would be on the form. Trying to work through it now.
 
youve got it in reverse logic:

If (IsNull(DLookup("[Username]", "Users", "[UserName] ='" & Me.EnterExistingUsername.Value & "' And PIN = '" & Me.EnterPin.Value & "'"))) Then
MsgBox "Fail"
Else
MsgBox "Win"
 
oh ok. I see what you mean. That worked a charm. Thanks for the help. :D
 

Users who are viewing this thread

Back
Top Bottom