Through other threads of asking and receiving help on my database it was suggested that I ditch the navigation form layout and go with tabbed controls.
I was finally able to figure out how to get all of the forms in the tabbed control and them function correctly. I was being stupid and was trying to copy and paste the form controls on the tab pages when I simply needed to drag and drop the entire forms on the pages. This is all fine but now I am trying to fix the permissions to the tabs by access level of the users.
Before I had multiple navigation forms that only had the "tabs" that the specific access level users needed to see so I had 5 different "main forms". When the user logged in the code checked to see what the users access level was and directed them tot he appropriate navigation form containing forms specific to their jobs.
Now that I have only one "main form" with all of the forms in the tabbed control... can someone help me with the code changes to only show the tabs related to the access levels?
Here is the "main form":
*Admin need access to all pages. tbl_accesslevel - AutoNumber field "ID"=1, field "AccessLvl"=Admin
*VisInspector needs access only to pages 1,5 & 6 tbl_accesslevel - AutoNumber field "ID"=2, field "AccessLvl"=VisInspector
*LabInspector needs access only to pages 2,5 & 6 tbl_accesslevel - AutoNumber field "ID"=3, field "AccessLvl"=LabInspector
*MultiInspector needs access only to pages 1,2,5 & 6 tbl_accesslevel - AutoNumber field "ID"=4, field "AccessLvl"=MultiInspector
*Engineer needs access only to pages 0 & 5 tbl_accesslevel - AutoNumber field "ID"=5, field "AccessLvl"=Engineer
in the code for the login form it used to look like this which checked their access level and directed them to the correct "main form" designed for that access level:
Does this make sense? This code still works if I create multiple "main forms" again but that is no different than using the navigation forms.
The profile parts of the code do not work though because the code in the main form has this code to open the frm_userprofile but the reference is to a navigation subform and I had to comment the openargs part out or I get an error: (this main navigation form was used only by admin the others were similar)
I was finally able to figure out how to get all of the forms in the tabbed control and them function correctly. I was being stupid and was trying to copy and paste the form controls on the tab pages when I simply needed to drag and drop the entire forms on the pages. This is all fine but now I am trying to fix the permissions to the tabs by access level of the users.
Before I had multiple navigation forms that only had the "tabs" that the specific access level users needed to see so I had 5 different "main forms". When the user logged in the code checked to see what the users access level was and directed them tot he appropriate navigation form containing forms specific to their jobs.
Now that I have only one "main form" with all of the forms in the tabbed control... can someone help me with the code changes to only show the tabs related to the access levels?
Here is the "main form":
*Admin need access to all pages. tbl_accesslevel - AutoNumber field "ID"=1, field "AccessLvl"=Admin
*VisInspector needs access only to pages 1,5 & 6 tbl_accesslevel - AutoNumber field "ID"=2, field "AccessLvl"=VisInspector
*LabInspector needs access only to pages 2,5 & 6 tbl_accesslevel - AutoNumber field "ID"=3, field "AccessLvl"=LabInspector
*MultiInspector needs access only to pages 1,2,5 & 6 tbl_accesslevel - AutoNumber field "ID"=4, field "AccessLvl"=MultiInspector
*Engineer needs access only to pages 0 & 5 tbl_accesslevel - AutoNumber field "ID"=5, field "AccessLvl"=Engineer
in the code for the login form it used to look like this which checked their access level and directed them to the correct "main form" designed for that access level:
Code:
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 & "'")
Select Case Credentials.AccessLvlID
Case 1
If showProfile() Then
DoCmd.OpenForm "frm_home", , , , , , "profile"
Else
DoCmd.OpenForm "frm_home"
End If
Case 2
If showProfile() Then
DoCmd.OpenForm "frm_visualinspector", , , , , , "profile"
Else
DoCmd.OpenForm "frm_visualinspector"
End If
Case 3
If showProfile() Then
DoCmd.OpenForm "frm_labinspector", , , , , , "profile"
Else
DoCmd.OpenForm "frm_labinspector"
End If
Case 4
If showProfile() Then
DoCmd.OpenForm "frm_multiinspector", , , , , , "profile"
Else
DoCmd.OpenForm "frm_multiinspector"
End If
Case 5
If showProfile() Then
DoCmd.OpenForm "frm_engineer", , , , , , "profile"
Else
DoCmd.OpenForm "frm_engineer"
End If
Case 6
MsgBox "Your Account Has Been Deactivated. Please Contact the Administrator."
Case Else
DoCmd.OpenForm "frm_loginform"
End Select
DoCmd.Close acForm, Me.Name
Else
MsgBox "Incorrect Login or Password"
End If
End If
End Sub
Private Function showProfile() As Boolean
Dim Password As Variant
Dim Question1 As Variant
Dim Answer1 As Variant
Dim Question2 As Variant
Dim Answer2 As Variant
Dim Question3 As Variant
Dim Answer3 As Variant
Password = DLookup("Password", "tbl_users", "UserName = '" & Credentials.UserName & "'")
Question1 = DLookup("Question1", "tbl_users", "UserName = '" & Credentials.UserName & "'")
Answer1 = DLookup("Answer1", "tbl_users", "UserName = '" & Credentials.UserName & "'")
Question2 = DLookup("Question2", "tbl_users", "UserName = '" & Credentials.UserName & "'")
Answer2 = DLookup("Answer2", "tbl_users", "UserName = '" & Credentials.UserName & "'")
Question3 = DLookup("Question3", "tbl_users", "UserName = '" & Credentials.UserName & "'")
Answer3 = DLookup("ID", "tbl_users", "UserName = '" & Credentials.UserName & "'")
showProfile = (Password = "password" Or IsNull(Question1) Or IsNull(Answer1) Or IsNull(Question2) Or IsNull(Answer2) Or IsNull(Question3) Or IsNull(Answer3))
End Function
Does this make sense? This code still works if I create multiple "main forms" again but that is no different than using the navigation forms.
The profile parts of the code do not work though because the code in the main form has this code to open the frm_userprofile but the reference is to a navigation subform and I had to comment the openargs part out or I get an error: (this main navigation form was used only by admin the others were similar)
Code:
Private Sub Form_Open(Cancel As Integer)
If Credentials.AccessLvlID <> 1 Then
DoCmd.OpenForm "frm_loginform"
Cancel = 1
End If
If OpenArgs = "profile" Then
DoCmd.BrowseTo acBrowseToForm, "frm_userprofile", "frm_home.NavigationSubform"
End If
End Sub
Attachments
Last edited: