User/Password Table to log in

chris01252

Registered User.
Local time
Today, 06:47
Joined
Feb 27, 2007
Messages
43
I found another thread which answered my question about creating a log in: See Thread

Only problem is I can't seem to get it to work can you please take a look at this line of code and see if you can spot an error, I think this is where it is occuring

Code:
If Me.txtpassword.Value = DLookup("Password", "tblUsers", "[UserID]= """ & txtUserName & """" Then

The full code is as follows, incase the error is elsewhere

Code:
Private Sub cmdLogin_Click()

If IsNull(Me.txtusername) Or Me.txtusername = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.txtusername.SetFocus
Exit Sub
End If

'Check to see if data is entered into the password box
If IsNull(Me.txtpassword) Or Me.txtpassword = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Me.txtpassword.SetFocus
Exit Sub
End If

If Me.txtpassword.Value = DLookup("Password", "tblUsers", "[UserID]= """ & txtUserName & """" Then

DoCmd.Close acForm, "frmLogIn", acSaveNo
DoCmd.OpenForm "frmStockControllerSignOff"

Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
Me.txtpassword.SetFocus
End If
End Sub
 
Try this:

If Me.txtpassword.Value = DLookup("Password", "tblUsers", "[UserID]= """ & txtUserName & """") Then
 
Is UserID a numeric or text data type in the table? In any case you have to close the parentheses, as already noted.
 
Cheers guys got it working now.

One other point is there anyway I can do the following:

I have added to my user table another field 'StartForm' and this is basically the name of a form so depending on who logs in will depend on which form it takes them to.

I believe it would be this line that needs to be edited:

DoCmd.OpenForm "frmStockControllerSignOff"

Any help would be much appreciated!
 
Sure; declare a string variable (strStartForm for example), set it's value using DLookup, and use it when opening the form:

DoCmd.OpenForm strStartForm

If you're comfortable with them, I'd use a recordset to get the password and start form.
 
Can you tell/show me how I would 'declare a string variable', I promise I am not lazy I think this is just beyond my skill level atm.

No idea about record sets either :(
 
You'll find VBA Help to be a valuable tool:
 

Attachments

  • Declare.JPG
    Declare.JPG
    20.6 KB · Views: 123

Users who are viewing this thread

Back
Top Bottom