Solved dlookup multi criteria

AsMok

IT IS ME ^_^
Local time
Today, 10:37
Joined
Sep 4, 2019
Messages
67
Hi all
i have this part of login code.
.
.
If SN.Value = ********** And Me.PASSWORD = DLookup("[PASSWORD]", "USERS", "[NAME]='" & Me.Des & "'") Then
Me.Visible = False
DoCmd.OpenForm "**********", acNormal
.
.

It works great But now I need to add yes/no field as a criteria ( I did it as the following) ..it keep giving me a syntax error

If SN.Value = ********** And Me.PASSWORD = DLookup("[PASSWORD]", "USERS", "[NAME]='" & Me.Des & "'" & "[activation]=True") Then
Me.Visible = False
DoCmd.OpenForm "**********", acNormal
.

.
thanks in advance for help
 
There's 2 different concatenation operators in play here.

& : is used to combine elements of a string together
---> ("Hello " & UserNameVariable & ", You are now signed in")

AND : is used to combine elements of logic together
---> Iif(A>.5 AND B<2, "Pass", "Fail")

So, inside your Dlookup you need to use 'AND' to join your 2 criteria to each other (like how you did between the SN.Value=****& AND Me.PASSWORD... part of your code). Put an 'AND' inside quote marks so that it appears between the NAME check and the activation check.
 
There's 2 different concatenation operators in play here.

& : is used to combine elements of a string together
---> ("Hello " & UserNameVariable & ", You are now signed in")

AND : is used to combine elements of logic together
---> Iif(A>.5 AND B<2, "Pass", "Fail")

So, inside your Dlookup you need to use 'AND' to join your 2 criteria to each other (like how you did between the SN.Value=****& AND Me.PASSWORD... part of your code). Put an 'AND' inside quote marks so that it appears between the NAME check and the activation check.
Many thanks for your quick accurate reply 🙏
It works now (y)

If SN.Value = **** And Me.PASSWORD = DLookup("[PASSWORD]", "USERS", "[NAME]='" & Me.Des & "' AND [activation] = True") Then
 
Last edited:
On a separate note, if you intend your passwords to be case-sensitive then use StrComp() function and pass vbBinaryCompare to the last argument to test the entered PW is correct:
Code:
If SN.Value = **** And StrComp(Me.PASSWORD, DLookup("[PASSWORD]", "USERS", "[NAME]='" & Me.Des & "' AND [activation] = True"), vbBinaryCompare) = 0 Then
Otherwise "Pa$$w0rd" and "PA$$W0RD" will be considered the same 😖
 
On a separate note, if you intend your passwords to be case-sensitive then use StrComp() function and pass vbBinaryCompare to the last argument to test the entered PW is correct:
Code:
If SN.Value = **** And StrComp(Me.PASSWORD, DLookup("[PASSWORD]", "USERS", "[NAME]='" & Me.Des & "' AND [activation] = True"), vbBinaryCompare) = 0 Then
Otherwise "Pa$$w0rd" and "PA$$W0RD" will be considered the same 😖
great suggestion.... many thanks 🙏
 

Users who are viewing this thread

Back
Top Bottom