psyc0tic1
MajP's code is based off of a passed "AccLvl". What are you passing it? He has it set up to accept a string but is checking for numeric values.
Interesting that even worked, did not catch that mistake. I get that passing the numeric 0 into the string argument casts it into a string "0". But then the select case seems to cast it back.MajP's code is based off of a passed "AccLvl". What are you passing it? He has it set up to accept a string but is checking for numeric values.
SetAccess CInt(Me.OpenArgs)
Public Sub SetAccess(AccLvl As Integer)
Not suggesting you use a pull down, that was just for demo purposes. I cannot replicate getting your login values. You already have the code to get the acclvlID. Not open your single tabbed form passing in the acclvlID, instead of opening a bunch of different forms depending on permissions. Basically replace the select case with a single call to open the tabbed form.So... my database recognizes who just logged in shown by the login code I posted in post #9. From post #1 I showed the login form code I had previously which directed users to individual navigation forms based on their AccessLvlID.
I don't allow users to choose their "roles" e.g. visual inspector, lab tester etc. from drop down boxes... I need the code to check the tbl_users for their AccessLevel (field name) and then display the pages they need to see
So... my database recognizes who just logged in shown by the login code I posted in post #9. From post #1 I showed the login form code I had previously which directed users to individual navigation forms based on their AccessLvlID.
I don't allow users to choose their "roles" e.g. visual inspector, lab tester etc. from drop down boxes... I need the code to check the tbl_users for their AccessLevel (field name) and then display the pages they need to see.
I do not know anything about the openargs part but I have started reading about it and at the moment I do not get it.
Is it not possible for the main form to remember who just logged in and set page visibility based on their AccessLevel (field name in tbl_users)?
In my demo and since openargs is a string I was passing in "1", "2", but mistakenly also passed in 0. So I get how that was cast. But in the select case, I was surprised that the numeric checks workedDid you pass his code Credentials.AccessLvlID? I am guessing he'd left it as "String" as you've never posted what Credentials.AccessLvlID is defined as. The CASE using numbers is based off of your original sample but if he played it safe ACCESS is pretty good at understanding 2 = "2" in most cases.
Not suggesting you use a pull down, that was just for demo purposes. I cannot replicate getting your login values. You already have the code to get the acclvlID. Not open your single tabbed form passing in the acclvlID, instead of opening a bunch of different forms depending on permissions. Basically replace the select case with a single call to open the tabbed form.
Private Sub Command1_Click()
If IsNull(Me.txtLoginID) Then
MsgBox "Please Enter Login", vbInformation, "Need ID"
Me.txtLoginID.SetFocus
ElseIf IsNull(Me.txtPassword) Then
MsgBox "Please Enter Password", vbInformation, "Need Password"
Me.txtPassword.SetFocus
Else
Credentials.UserName = Me.txtLoginID.Value
If DLookup("Password", "tbl_users", "UserName = '" & Credentials.UserName & "'") = Me.txtPassword Then
Credentials.UserId = DLookup("ID", "tbl_users", "UserName = '" & Credentials.UserName & "'")
Credentials.AccessLvlID = DLookup("AccessLvl", "tbl_users", "UserName = '" & Credentials.UserName & "'")
DoCmd.OpenForm "frm_home"
DoCmd.Close acForm, Me.Name
End If
End If
End Sub
Public Sub Form_Open()
If Credentials.AccessLvlID = DLookup("AccessLvl", "tbl_users", "UserName = '" & Credentials.UserName & "'") Then
Select Case Credentials.AccessLvlID
Case 1
tb.Pages(0).Visible = True
tb.Pages(1).Visible = True
tb.Pages(2).Visible = True
tb.Pages(3).Visible = True
tb.Pages(4).Visible = True
tb.Pages(5).Visible = True
tb.Pages(6).Visible = True
Case 2 'Visual inspection
tb.Pages(0).Visible = False
tb.Pages(1).Visible = True
tb.Pages(2).Visible = False
tb.Pages(3).Visible = False
tb.Pages(4).Visible = False
tb.Pages(5).Visible = True
tb.Pages(6).Visible = True
Case 3 ' Lab Inspector
tb.Pages(0).Visible = False
tb.Pages(1).Visible = False
tb.Pages(2).Visible = True
tb.Pages(3).Visible = False
tb.Pages(4).Visible = False
tb.Pages(5).Visible = True
tb.Pages(6).Visible = True
Case 4 'Multi Inspector
tb.Pages(0).Visible = False
tb.Pages(1).Visible = True
tb.Pages(2).Visible = True
tb.Pages(3).Visible = False
tb.Pages(4).Visible = False
tb.Pages(5).Visible = True
tb.Pages(6).Visible = True
Case 5 'Engineer
tb.Pages(0).Visible = True
tb.Pages(1).Visible = False
tb.Pages(2).Visible = False
tb.Pages(3).Visible = False
tb.Pages(4).Visible = False
tb.Pages(5).Visible = True
tb.Pages(6).Visible = False
End Select
End If
End Sub
Option Compare Database
Private Sub Form_Open(Cancel As Integer)
If Credentials.AccessLvlID <> 1 And Credentials.AccessLvlID <> 2 And Credentials.AccessLvlID <> 3 And Credentials.AccessLvlID <> 4 And Credentials.AccessLvlID <> 5 Then
DoCmd.OpenForm "Login Form"
Cancel = 1
End If
End Sub
Public Sub Form_Load()
Const TabName = "TabCtl87"
Dim pg As Access.Page
Dim tb As Access.TabControl
Set tb = Me.Controls(TabName)
If Credentials.AccessLvlID = DLookup("AccessLvl", "tbl_users", "UserName = '" & Credentials.UserName & "'") Then
Select Case Credentials.AccessLvlID
Case 1
tb.Pages(0).Visible = True
tb.Pages(1).Visible = True
tb.Pages(2).Visible = True
tb.Pages(3).Visible = True
tb.Pages(4).Visible = True
tb.Pages(5).Visible = True
tb.Pages(6).Visible = True
Case 2 'Visual inspection
tb.Pages(0).Visible = False
tb.Pages(1).Visible = True
tb.Pages(2).Visible = False
tb.Pages(3).Visible = False
tb.Pages(4).Visible = False
tb.Pages(5).Visible = True
tb.Pages(6).Visible = True
Case 3 ' Lab Inspector
tb.Pages(0).Visible = False
tb.Pages(1).Visible = False
tb.Pages(2).Visible = True
tb.Pages(3).Visible = False
tb.Pages(4).Visible = False
tb.Pages(5).Visible = True
tb.Pages(6).Visible = True
Case 4 'Multi Inspector
tb.Pages(0).Visible = False
tb.Pages(1).Visible = True
tb.Pages(2).Visible = True
tb.Pages(3).Visible = False
tb.Pages(4).Visible = False
tb.Pages(5).Visible = True
tb.Pages(6).Visible = True
Case 5 'Engineer
tb.Pages(0).Visible = True
tb.Pages(1).Visible = False
tb.Pages(2).Visible = False
tb.Pages(3).Visible = False
tb.Pages(4).Visible = False
tb.Pages(5).Visible = True
tb.Pages(6).Visible = False
End Select
End If
End Sub
Private Sub Command1_Click()
Dim AccLvl As Integer
If IsNull(Me.txtLoginID) Then
MsgBox "Please Enter Login", vbInformation, "Need ID"
Me.txtLoginID.SetFocus
ElseIf IsNull(Me.txtPassword) Then
MsgBox "Please Enter Password", vbInformation, "Need Password"
Me.txtPassword.SetFocus
Else
Credentials.UserName = Me.txtLoginID.Value
If DLookup("Password", "tbl_users", "UserName = '" & Credentials.UserName & "'") = Me.txtPassword Then
Credentials.UserId = DLookup("ID", "tbl_users", "UserName = '" & Credentials.UserName & "'")
'Credentials.AccessLvlID = DLookup("AccessLvl", "tbl_users", "UserName = '" & Credentials.UserName & "'")
'Get the access level and pass it to the form in the using open args which is the 7th argument of the Docmd.openform
[B][COLOR="Red"] AccLvl = DLookup("ID", "tbl_users", "UserName = '" & Credentials.UserName & "'")
DoCmd.OpenForm "frm_home", , , , , , AccLvl[/COLOR][/B]
DoCmd.Close acForm, Me.Name
End If
End If
End Sub