Login Form in Access

furnitureheaven

Registered User.
Local time
Today, 14:19
Joined
Aug 5, 2008
Messages
36
hi

Hi
I am new in access, I have a database in access and design some forms, I have just create a user login form. If user “Akoo” login the “frm_sara” will open and other user login with user name and password then “frm_lynn” should open. I have tried but due to limited knowledge in access, could not successful.

here is a VBA Code, for login authantication.

On form there a combo box for user name and text box for password. the following code is run on Command button. In database there is a 4 column,

UserID
Name
Password
SecurityLevel

so what is want if UserID is 1 then open frm_Sara and if its 2 then open frm_Lynn.

Code:
If DLookup("Password", "Users", "[Name]=" & Me.user_id.Value) Then

      Name = Me.user_id.Value
        
       'DoCmd.OpenForm "frm_sara", acNormal = acNormal
       
'Close logon form and open splash screen
        DoCmd.SetWarnings (0)
        DoCmd.Close acForm, "frm_main", acSaveNo
        DoCmd.OpenForm "frm_sarah"

        Else
       MsgBox "Password Invalid.  Please Try Again", vbOKOnly, "Invalid Entry!"
        Me.password.SetFocus
    End If
 
Please do not post the same problem multiple times .. remember help here is free and everyone has other jobs and only reply in their free time and it really doesn't make anyone inclined to help any faster or at all. =]

You can use something akin to the following in your OnClick() event of the login button.

Code:
Dim sPassword As String
Dim sFormName As String
 
sPassword = DLookup("[PasswordField]", "TableUsers", _
"[UserLoginName] = '" & Me!ComboLoginBoxName & "'
 
 
If sPassword = Me!txtPasswordControl Then
[INDENT]Select Case Me!ComboLoginBoxName 
 
Case "Akoo"
[INDENT]sFormName = "frmAkooFormName"
[/INDENT]Case "Mojo"
[INDENT]sFormName = "frmMojoFormName"
[/INDENT]Case "Akumboo"
[INDENT]sFormName = "frmAkumbooFormName"
[/INDENT]End Select
[/INDENT]Else 
[INDENT]MsgBox "The password was incorrect.", , "Incorrect Password"
Me!txtPasswordControl.SetFocus
[/INDENT]End If
 
DoCmd.OpenForm sFormName 
DoCmd.Close


-dK
 
You also need to change your field called Name to something else! Name is a Reserved Word in Access, and you'll get in trouble with the Access gnomes, sooner or later, probably sooner. Problems caused by using Reserved Words as object names can be a real bear to sort out!
 
following code i have done, but still got error, the error is

Compile Error:- End IF without block if.

Code is

Code:
Dim password As String
password = DLookup("UPassword", "Users", "[UserName]='" & Me.UserName.Value & "'")
If password = Me!Upasswordcontrol Then Select Case Me![UserName]
    Case "Akmal" = "frm_sara"
    Case "Lynn" = "frm_lynn"
End Select
 
Else
    MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
    Me.password.SetFocus
End If
 
DoCmd.OpenForm "frm_main"
DoCmd.Close
End Sub
 
There is a problem with your IF statements. Or your End If. Maybe put End Select on a line above End If.
 
That's because you didn't take my recommendations seriously. I am not sure why you are getting that error unless you have some other things going on in your form. I can see some other errors so am going to shortcut and just fix to your specifications.

So, in conclusion, I am posting a sample db using your naming convention for the tables but used standard naming convention for the form controls because it was too confusing for me in your code.

I went ahead and took an extra step to mitigate another posting by making sure there would be kick back prompts if the user went happy clicking on the login button prior to entering anything in the form controls.

Open the frm_main, it should do what you want it to do. The password is the user first initial ("akbal" -> "a", "lynn" -> "l").

Hope this helps.

-dK
 
Last edited:

Users who are viewing this thread

Back
Top Bottom