How to open specific form depending on User Level/Access Level (1 Viewer)

lacampeona

Registered User.
Local time
Today, 01:17
Joined
Dec 28, 2015
Messages
392
Hello
I have login form PasswordLogin RC4 5.3 version from user IslaDogs , the login form has 3 access levels.

1. Default User
2. Administrator
3. Developer

when user login i want to hide ribbon and want to open specific form to him, and dirrent form for admin and different form for developer. I put the code in the end of the cmdLogin procedure, i also have to put Dim AccessLevel as Integer no? i try it and now i have always ribbon hidden...the code is not listening me...i enter with admin and i dont have ribbon the same for default user...

how i have to write to make the code work? Is something like that? many thanks in the advance


If AccessLevel = 2 Then

DoCmd.ShowToolbar "Ribbon", acToolbarYes
DoCmd.OpenForm "GlavniMeni"

Else
DoCmd.ShowToolbar "Ribbon", acToolbarNo
DoCmd.OpenForm "GlavniMeni"

End If

Exit_Handler:
Exit Sub

Err_Handler:
MsgBox "Error " & Err.Number & " in cmdLogin_Click procedure: " & Err.Description
Resume Exit_Handler

End Sub
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 16:17
Joined
Oct 29, 2018
Messages
21,454
Hi. Do you know how to "step-through" the code? You might have to.
 

lacampeona

Registered User.
Local time
Today, 01:17
Joined
Dec 28, 2015
Messages
392
Hi,
hmmm how I do that?
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 16:17
Joined
Oct 29, 2018
Messages
21,454
Hi,
hmmm how I do that?
When you view your code, click on the left side of the line If AccessLevel = 2 Then. You should get a red dot that looks like this:

break.PNG


You would then run your code (by opening the form and logging in), and it should pause the code at that line. You could then hit the F8 key to run the code one line at a time, so you can see what's happening.
 

lacampeona

Registered User.
Local time
Today, 01:17
Joined
Dec 28, 2015
Messages
392
I didnt know that. Thanks, I try your advice and now I am seing problems with yellow color... :(
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 16:17
Joined
Oct 29, 2018
Messages
21,454
I didnt know that. Thanks, I try your advice and now I am seing problems with yellow color... :(
Yes, the yellow color "highlights" the next line that will be executed when you press the F8 key. While the code is suspended, you can hover your mouse over the variables or form references to see their values. You can also use the Immediate Window to enter some expressions to verify what you think the code should be seeing.
 

zeroaccess

Active member
Local time
Yesterday, 18:17
Joined
Jan 30, 2020
Messages
671
Not sure if this helps, but here is my module that handles this stuff:

Code:
Option Compare Database
Option Explicit

Public Enum PrivilegeEnum
    User_Privilege = 1
    Analyst_Privilege = 2
    Administrator_Privilege = 3
End Enum

Private Function EmployeeHas(UserID As Long, RoleID As PrivilegeEnum) As Boolean
    EmployeeHas = DCountWrapper("*", "tblUsers", "[User ID]=" & UserID & " AND [Role]=" & RoleID) > 0
End Function

Public Function IsUser() As Boolean
   
    IsUser = EmployeeHas(GetCurrentUserID(), User_Privilege)

End Function

Public Function IsAnalyst() As Boolean
   
    IsAnalyst = EmployeeHas(GetCurrentUserID(), Analyst_Privilege)

End Function

Public Function IsAdministrator() As Boolean

    IsAdministrator = EmployeeHas(GetCurrentUserID(), Administrator_Privilege)
   
End Function

Public Function GetCurrentUserID() As Long
    GetCurrentUserID = Nz(TempVars![CurrentUserID], 0)
End Function

CurrentUserID is assigned to a TempVar on the click of the Login button.

An example of privilege in use:

Code:
    Me.cmdEdit.Enabled = IsAdministrator Or IsAnalyst
 

isladogs

MVP / VIP
Local time
Today, 00:17
Joined
Jan 14, 2017
Messages
18,209
Hi Elena
Add this function to modFunctions
Code:
Public Function GetAccessLevel()
    'zero before login
    GetAccessLevel = Nz(DLookup("AccessLevel", "tblUsers", "UserName='" & GetUserName & "'"), 0)

End Function

Now change the First line of your code to

Code:
If GetAccessLevel = 2 Then

For info, I normally put code like that in the DoLogin procedure after the line Call LogMeIn.
That makes it easier to track actions to be done after clicking the Login button
 

lacampeona

Registered User.
Local time
Today, 01:17
Joined
Dec 28, 2015
Messages
392
Hellooo yess is working IslaDogs.
Thank you again
Elena

thank you also zeroaccess I will save your code if sometimes I will need it.
 

isladogs

MVP / VIP
Local time
Today, 00:17
Joined
Jan 14, 2017
Messages
18,209
You're welcome.
I started working on a Pro version with additional features about a year or so ago but never got around to finishing it.
However that was part of the code I had already done
If you have further questions/suggestions, I suggest you contact me via a PM (conversation) or email me as I may be able to provide the answer quickly.
 

Users who are viewing this thread

Top Bottom