By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,483 Members | 1,574 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,483 IT Pros & Developers. It's quick & easy.

Access Levels: having different views for different logins

P: 6
Hi all,

Im creating a database in access for a fictional sports centre. What i would like help on is having different views for different logins. So, if i typed in the managers username and password, i would be able to see ALL buttons, if i typed in an admin accounts username and password, i would only be able to see some buttons and the others have disappeared.

I know how to set things so they cant be seen:

........Visible = False or True......

but cant seem to attached it to users.

Any help?

Thanks.

Tej
Feb 13 '08 #1
Share this Question
Share on Google+
3 Replies


jaxjagfan
Expert 100+
P: 254
Hi all,

Im creating a database in access for a fictional sports centre. What i would like help on is having different views for different logins. So, if i typed in the managers username and password, i would be able to see ALL buttons, if i typed in an admin accounts username and password, i would only be able to see some buttons and the others have disappeared.

I know how to set things so they cant be seen:

........Visible = False or True......

but cant seem to attached it to users.

Any help?

Thanks.

Tej
You will need a user table and a user group table. Each user will belong to a group you will establish for your app.

tblUser
UserID, Login, Name, GroupID, Password (Set format of password field to "Password" so it is displayed as "******"). Login will be their user login (IE rrabbit)

tblUserGroup
GroupID, Group

A module with a Public variable - Public iGrp as Integer.

Unbound Form - frmLogin. First form that displays in app. Has 2 textboxes (txtLogin, txtPass) and 2 command buttons(cmdOK, cmdCancel). When User enters Login, Password and Clicks Ok you will need a DLookup to ensure correct password in tblUser.

When correct password is acceptable then a second DLookup to get GroupID
from tblUser.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdLogin_Click()
  2. If Me.Pass <> Dlookup("[Password]","tblUser","[Login] ='" & Me.txtLogin & "'") Then
  3. Msgbox "Incorrect Password - Try Again!"
  4. Me.txtPass.SetFocus
  5. Exit Sub
  6. Else
  7. iGrp = Dlookup("[GroupID]","tblUser","[Login] ='" & Me.txtLogin & "'")
  8. Docmd.OpenForm "YourMenuForm"
  9. End Sub
  10.  
In the menu form you will need a function or Case statement to control what gets turned on or off according to iGrp.

Expand|Select|Wrap|Line Numbers
  1. Select Case iGrp
  2. Case 1
  3. Me.cmdOpenMgr.visible = False
  4. Case 2
  5. Me.cmdOpenMgr.visible = True
  6. End Select
  7.  
I have apps which get the Windows UserID and then looks up the group and goes from there. No login form required.

Hope this helps!
Feb 13 '08 #2

P: 6
You will need a user table and a user group table. Each user will belong to a group you will establish for your app.

tblUser
UserID, Login, Name, GroupID, Password (Set format of password field to "Password" so it is displayed as "******"). Login will be their user login (IE rrabbit)

tblUserGroup
GroupID, Group

A module with a Public variable - Public iGrp as Integer.

Unbound Form - frmLogin. First form that displays in app. Has 2 textboxes (txtLogin, txtPass) and 2 command buttons(cmdOK, cmdCancel). When User enters Login, Password and Clicks Ok you will need a DLookup to ensure correct password in tblUser.

When correct password is acceptable then a second DLookup to get GroupID
from tblUser.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdLogin_Click()
  2. If Me.Pass <> Dlookup("[Password]","tblUser","[Login] ='" & Me.txtLogin & "'") Then
  3. Msgbox "Incorrect Password - Try Again!"
  4. Me.txtPass.SetFocus
  5. Exit Sub
  6. Else
  7. iGrp = Dlookup("[GroupID]","tblUser","[Login] ='" & Me.txtLogin & "'")
  8. Docmd.OpenForm "YourMenuForm"
  9. End Sub
  10.  
In the menu form you will need a function or Case statement to control what gets turned on or off according to iGrp.

Expand|Select|Wrap|Line Numbers
  1. Select Case iGrp
  2. Case 1
  3. Me.cmdOpenMgr.visible = False
  4. Case 2
  5. Me.cmdOpenMgr.visible = True
  6. End Select
  7.  
I have apps which get the Windows UserID and then looks up the group and goes from there. No login form required.

Hope this helps!

Thank you for that mate. I will have a go and get back to you.

Cheers

Tej
Feb 13 '08 #3

P: 6
Hi jaxjagfan

Im still having some trouble. I got up to the point at which im able to login with different accounts. Here is the code:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Private intLogonAttempts As Integer
  3.  
  4. Private Sub Form_Open(Cancel As Integer)
  5. Me.cboUser.SetFocus
  6. End Sub
  7.  
  8. Private Sub cboUser_AfterUpdate()
  9. Me.txtPassword.SetFocus
  10. End Sub
  11.  
  12. Private Sub cmdLogin_Click()
  13.  
  14.     If IsNull(Me.cboUser) Or Me.cboUser = "" Then
  15.             MsgBox "You must enter a User Name.", vbOKOnly, "Need a Username"
  16.             Me.cboUser.SetFocus
  17.         Exit Sub
  18.     End If
  19.     If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
  20.             MsgBox "You must enter a Password.", vbOKOnly, "Need a password"
  21.             Me.txtPassword.SetFocus
  22.         Exit Sub
  23.     End If
  24.  
  25.     If Me.txtPassword.Value = DLookup("password", "tblUsers", "[userID]=" & Me.cboUser.Value) Then
  26.  
  27.         myUserID = Me.cboUser.Value
  28.  
  29.         DoCmd.Close acForm, "frmLogon", acSaveNo
  30.         DoCmd.OpenForm "frmMainMenu"
  31.  
  32.         Else
  33.         MsgBox "Password Invalid.  Please Try Again", vbOKOnly, "Invalid Entry!"
  34.         Me.txtPassword.SetFocus
  35.     End If
  36. End Sub
  37.  
Ive created my main menu form which has button1, button2, button3 etc.

Ive also created similar code to what you said:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2.  
  3.     If accessLevelID = 1 Then
  4.     Me.button1.Visible = True
  5.     Me.button2.Visible = True
  6.  
  7.     Else
  8.     Me.button1.Visible = False
  9.     Me.button2.Visible = False
  10.  
  11.     End If
  12.  
  13. End Sub
  14.  

......right, but i cant catch what username was chosen in the drop-down menu with its access level id to get the chosen buttons displayed.

The following attributes are in tblUser:

userID
surname
firstname
accessLevelID

>>> with accessLevelID being 1 for Admin, 2 general user etc

If its not a problem, i could use some help.

Thanks

Tej
Feb 14 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.