I've seen many similar threads, but despite repeated efforts I cannot figure out my problem. I am running Access 2003, VB 6.5, Office XP Pro. Code excerpt is below (you can see where I've tried debugging myself). My problem is in the DLookup command.
UserName = Me.cboUserName. Value
Debug.Print "User Name is "; UserName
strPassword = DLookup("Passwo rd", "Employees" , "EmpName ='" & UserName)
Debug.Print "Password is "; Password
If Me.txtPassword. Value = strPassword Then
DoCmd.Close acForm, "DatabaseLogin" , acSaveNo
DoCmd.OpenForm "MenuMain", acViewNormal
Exit Sub
"cboUserNam e" is a combo box on form "DatabaseLogin" . That is working fine. On same form users enter a password into text box "txtPasswor d". I am attempting to compare value of "txtPasswor d" to a cell "Password" in table "Employees" where "EmpName" is equal to value of "cboUserNam e". For explanation purposes only, let's say value of "cboUserNam e" is "Davis". With syntax as shown above, I receive error message {Syntax error in string in query expression 'EmpName ='Davis'.} (items inside braces are verbatim). "EmpName" is a text field. "Password" is also a text field.
I have tried multilple variations of syntax, getting other error messages in the process (compile error, you canceled the previous operation ,etc.). What am I doing wrong? Thanks in advance for your help.
UserName = Me.cboUserName. Value
Debug.Print "User Name is "; UserName
strPassword = DLookup("Passwo rd", "Employees" , "EmpName ='" & UserName)
Debug.Print "Password is "; Password
If Me.txtPassword. Value = strPassword Then
DoCmd.Close acForm, "DatabaseLogin" , acSaveNo
DoCmd.OpenForm "MenuMain", acViewNormal
Exit Sub
"cboUserNam e" is a combo box on form "DatabaseLogin" . That is working fine. On same form users enter a password into text box "txtPasswor d". I am attempting to compare value of "txtPasswor d" to a cell "Password" in table "Employees" where "EmpName" is equal to value of "cboUserNam e". For explanation purposes only, let's say value of "cboUserNam e" is "Davis". With syntax as shown above, I receive error message {Syntax error in string in query expression 'EmpName ='Davis'.} (items inside braces are verbatim). "EmpName" is a text field. "Password" is also a text field.
I have tried multilple variations of syntax, getting other error messages in the process (compile error, you canceled the previous operation ,etc.). What am I doing wrong? Thanks in advance for your help.
Comment