VBA DLOOKUP Function

shamas21

Registered User.
Local time
Today, 17:47
Joined
May 27, 2008
Messages
162
Hi All

In have a form that request the user to type the username and password before being able to enter the main screen.

However, the username and password are located in a table called tblLogin. Im trying to match of the username from the form with the password within the table, and if there is a match then they can enter.

My table has 3 columns - ID | Employee | Password

i have the following code but it will not execute.

Dim sPass As Boolean

sPass = DLookup(Me.cbxEmployee, "tblLogin", "password = " & Me.lblPassword)

Please can someone help, thanks
 
A few things -

1. You need to pass the user name to find out if the password supplied is correct.

2. you need to compare the password in the table to the password supplied.


For example:

Code:
Function CheckLoginPWD(sUserName As String, sPWDSupplied As String) As Boolean
Dim sPass As String



sPass = DLookup("[password]", "tblLogin", "[username] = '" & sUserName & "'")

If sPass = sPWDSupplied Then

    CheckLoginPWD = True
Else
    CheckLoginPWD = False
End If
End Function

Then you call it by:

Code:
CheckLoginPWD Me.cbxEmployee, Me.lblPassword
 
A few things -

1. You need to pass the user name to find out if the password supplied is correct.

2. you need to compare the password in the table to the password supplied.


For example:

Code:
Function CheckLoginPWD(sUserName As String, sPWDSupplied As String) As Boolean
Dim sPass As String
 
 
 
sPass = DLookup("[password]", "tblLogin", "[username] = '" & sUserName & "'")
 
If sPass = sPWDSupplied Then
 
    CheckLoginPWD = True
Else
    CheckLoginPWD = False
End If
End Function

Then you call it by:

Code:
CheckLoginPWD Me.cbxEmployee, Me.lblPassword

thanks Bob, it works great.

Just for my own interest, why have you put the [password] and [username] in brackets but you left "tblLogin" in quotes?
 

Users who are viewing this thread

Back
Top Bottom