login, how to send to different forms?

behedwin

Active Member
Joined
Dec 10, 2014
Messages
399
Hey

I want a simple login screen for my access file.

I have it all working with users in a table.

this code works fine
Code:
    If Me.txtPassword.Value = DLookup("Password", "Access_Table", "[User_ID]=" & Me.txtUsername.Value) Then
 
        lngMyEmpID = Me.txtUsername.Value

'Close logon form and open splash screen
        
        DoCmd.Close acForm, "Login_Form", acSaveNo
        DoCmd.OpenForm "Main_Form"

        Else
        MsgBox "Password Invalid.  Please Try Again", vbOKOnly, "Invalid Entry!"
        Me.txtPassword.SetFocus
    End If


but i want to add another "if" statement if the login is correct.
I have a column in my access_table (where user info is stored) that is named "Role"

I want to send the user to different forms if he types in correct username and password.
If Role = Admin
go to xxxx form
If Role = User
go to yyyy form

how to ad this to my code?
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
DLookup the role. How to use depends on what the possibilities are. If many, assign to a variable and write a bunch of If blocks or a Select Case block.
Or, if only 2 possibilities:
Code:
If DLookup("Role", "Access_Table", "[User_ID]=" & Me.txtUsername.Value) = "User" Then
  DoCmd.OpenForm "yyyy"
Else
  DoCmd.OpenForm "xxxx"
End If

You don't need .Value to know the value of a text or combo box. It's the default property. Also, I try to avoid writing multiple instances of a reference such as Me.txtUsername. 1 or 2, OK. Otherwise,
Code:
Dim lngUsrID As Long <-looks to me like it should be a number, not text
lngUsrID = Me.txtUsername <- but the control name suggests it's text??

If DLookup("Role", "Access_Table", "[User_ID]=" & lngUserName)...
None of the above, nor your code, allows for the possibility that DLookup returns nothing
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top