I imagine you got that error because ADezii was using 'Custom Menu' as the variable name which you should have replaced with the name of your own menu. As he said it iss semi-suedo it wouldn't just run as is.
Is your login form separate to the 'main menu' form, or are they the same form with the menu hidden until valid login?
I have a setup whereby I use a login form which then closes and opens the main menu. I use the following code for login validation:
- Private Sub Login_Click()
-
-
'Check if the username field is empty.
-
If IsNull(Me.Username) Or Me.Username = "" Then
-
MsgBox "You must enter a Username.", vbOKOnly
-
Me.Username.SetFocus
-
Exit Sub
-
End If
-
-
'Check if the password field is empty.
-
If IsNull(Me.Password) Or Me.Password = "" Then
-
MsgBox "You must enter a Password.", vbOKOnly
-
Me.Password.SetFocus
-
Exit Sub
-
End If
-
-
'Confirm if the password is correct for the username entered.
-
If Me.Password = DLookup("Password", "tblUsers", "[UserName]= '" & Replace(Me.Username, "'", "''") & "'") Then
-
DoCmd.Close acForm, "Login Page"
-
DoCmd.OpenForm "Main Menu"
-
Else
-
MsgBox "Incorrect username or password. Please try again.", vbOKOnly + vbCritical, "Access Denied."
-
Me.Username.SetFocus
-
End If
-
-
End Sub
This works on the assumption that you have a table which stores your User details.
Note that this code includes the variable names that I use in my own code - these are the things which you should replace with the names of variables in YOUR code:
Login_Click = Login is the name of the button clicked to initiate this procedure. (The _Click suffix is not part of the name, it's just to make it clearer what I'm referring to)
(Likewise, the Me. prefix is not part of the name, it's just to make it clearer what I'm referring to)
Me.Username = Username field on the login form.
Me.Password = Password field on the login form.
tblUsers = The name of the table which stores the user details.
Password = Name of the Password column in the user table.
UserName = Name of the username column in the user table.
Main Menu = Name of my menu form.
Hope that helps.
Adam.