User login with access levels (1 Viewer)

FunkyMonk150

New member
Local time
Today, 23:19
Joined
Mar 24, 2009
Messages
2
Hi,

Im currently working on creating a user login page in access which i have got working. I now need to make it be able to check the username against its user access level in the table so that the correct main form can be opened.

I have done it before but have since forgotten how to do it. I have got a text box on the login form which i need to pull the access level number from the table when the user name is selected from the combo box above. This text box will then be hidden so that it cannot be seen/changed. A bit primative i know :)

Any help will be magnificant thanks :D
 

DevastatioN

Registered User.
Local time
Today, 19:19
Joined
Nov 21, 2007
Messages
242
If you want each user to open a different form, you can create a field in the Users table called "UserForm", which stores the name of the form they wish to use.

Then on the Login Code, once the user validates you can set the open form variable to be that of the form stored in the table.

For example if you're using recordsets to validate:

usrForm = !UserForm
DoCmd.OpenForm usrForm

Of with DLookup:

'Lookup the current user logged in
usrForm = DLookup("[UserForm]", "[tblUsers]", "[UserName] ='" & username & "'")

If your main forms all look very similar, but have different functions... I would really recommend having only one main form that all users open, however once the form opens, it checks the user logged in, and then displays buttons / functionalities depending.

In my userform, I have Yes/No fields for all the buttons on the main form that are optional, then do the following On Open Procedure:

'Lookup the current user logged in
username = DLookup("[LoggedIn]", "[tblCurrentUser]")

'Get the recordset of the username currently logged in
Set db = CurrentDb()
strSQL = "SELECT * FROM tblUsers WHERE ([UserID] = '" & username & "')"

Set rs = db.OpenRecordset(strSQL)

'If the user is supposed to have the Add/Edit Items button, show the button and place at leftTop
If rs("AddEditFileButton").Value = -1 Then
Me.btnAddEditItems.Visible = True
'Set leftTop for next button in list
leftTop = leftTop + 480
Else
Me.btnAddEditItems.Visible = False
End If

And so on. Note that the leftTop variable is used so I can set the height of the buttons, so that all the buttons appear in a line, and there are no "gaps" if a user doesn't have options that are normally placed in the middle of the button list.

Hopefully this helps.
 

FunkyMonk150

New member
Local time
Today, 23:19
Joined
Mar 24, 2009
Messages
2
Hi, I have this so far but it doesnt seem to be working, have i done it right?

If txtThePassword = DLookup("Password", "Logon Table", _
"[Username]=" & "User ID") Then

usrForm = DLookup("[User Access Level]", "[Logon Table]", "[Username] ='" & "User ID" & "'")
DoCmd.OpenForm usrForm

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


The User Access Level is a text field in the table which has the name of the form i want to open for each access level
Thankyou
 
Last edited:

Users who are viewing this thread

Top Bottom