Access denied form , is still opening on a navigation form by click on navigation button

Ihk

Member
Local time
Today, 06:53
Joined
Apr 7, 2020
Messages
280
Hi,

I have database with Multiuser login system with different user roles.

1) Main Page or Dashboard has navigation buttons to open different forms.

2) One one the different forms (Name: MainOrderEntriesSheet), I have blocked for certain user level by following code.

Code:
Private Sub Form_Click()
Dim UserLevel As Integer

UserLevel = DLookup("UserRoles", "Users", "UserIDD = '" & Me.textUser.Value & "'")
    If UserLevel = 1 Then
          
            DoCmd.Close acForm, "MainOrderEntriesSheet", acSaveNo
    End If
End Sub



Private Sub Form_Load()
Dim UserLevel As Integer

UserLevel = DLookup("UserRoles", "Users", "UserIDD = '" & Me.textUser.Value & "'")
    If UserLevel = 1 Then
            
            MsgBox "Access Denied, Please contact System Administrator", vbCritical, "Not Allowed"
            DoCmd.Close acForm, "MainOrderEntriesSheet", acSaveNo
    End If
  
End Sub



Now, if user level 1, clicks on that form it does not open. So the code works well, by direct click on that form.

PROBLEM:

the same user can open that form on Navigation button of navigation form.

By 1st Click, message " Access denied......" appears , but then form opens up in the navigation page, which is blocked otherwise.

It tried to use the same code on Navigation button click, it does not work.

I am new to this , and need help.

Regards
 
you should put a Default UserLevel when the form loads:
Code:
Private Sub Form_Load()
Dim UserLevel As Integer

UserLevel = Nz(DLookup("UserRoles", "Users", "UserIDD = '" & Nz(Me.textUser.Value, "~@") & "'"), 1)
    If UserLevel = 1 Then
            
            MsgBox "Access Denied, Please contact System Administrator", vbCritical, "Not Allowed"
            DoCmd.Close acForm, "MainOrderEntriesSheet", acSaveNo
    End If
 
End Sub
 

Users who are viewing this thread

Back
Top Bottom