Matching values of fields with the data in the table

Naqibullah

Registered User.
Local time
Tomorrow, 01:36
Joined
Feb 7, 2013
Messages
86
Dear colleagues hope you all are doing well,
i have created a login form and create user page form, the tblListofUsers has two columns, UserName and Password, on the log in form when a user enters username and password, it should be matched with the tbllistofusers if true then msgbox"Welcome" else Msgbox "wrong username or password",
i have written following code but gives error
Regards

Private Sub Command5_Click()
If DLookup("UserName", "tblListOfUsers", "UserName = " & Forms![loginpageForm]!User) And DLookup("Password", "tblListOfUsers", "Password = " & Forms![loginpageForm]!passworduser) Then
MsgBox "You welcome"
Else
MsgBox "Wrong username or password"
End If
End Sub
 
You need to surround string values with '
Code:
If DLookup("UserName", "tblListOfUsers", "UserName = [B][COLOR=Red]'[/COLOR][/B]" & Forms![loginpageForm]!User) [B][COLOR=Red]& "'"[/COLOR][/B] And DLookup("Password", "tblListOfUsers", "Password =[B][COLOR=Red] '[/COLOR][/B]" & Forms![loginpageForm]!passworduser) [B][COLOR=Red]& "'"[/COLOR][/B] Then
 
thanks for reply
i have corrected the code but still error, the code which is corrected is below

If DLookup("UserName", "tblListOfUsers", "UserName = '" & Forms![loginpageForm]!User) & "'" And DLookup("Password", "tblListOfUsers", "Password = '" & Forms![loginpageForm]!passworduser) & "'" Then
 
And what is the error code and message?
 
Run-time error 3075
syntax error in string in query expression 'userName='peter'

Peter is a user name already created
 
I don't know which of the 2 DlookUp there cause the error, but Password is a reserved word in MS-Access.
Try to split up the 2 DlookUp in 2 parts to see which one cause the error, or post your database with some sample data, (zip it).
 
i checked it after splitting it as well, but still doesn't work
attached please find the db
Regards
 

Attachments

Ofcause it should be DCount and not DLookup, (and also the ending ) was placed wrong).
If DCount("UserName", "tblListOfUsers", "UserName ='" & Forms![loginpageForm]!User & "'") And DCount("Password", "tblListOfUsers", "Password = '" & Forms![loginpageForm]!passworduser & "'") Then
 

Users who are viewing this thread

Back
Top Bottom