Link to home
Start Free TrialLog in
Avatar of billcute
billcute

asked on

Restrict form Open failure

I currently placed the code below in the On Load Event of a form but when the form opens after a user "On Click event" in the Switchboard form and if the user's AccessID is greater than 3 then a msgbox tells user that he is "not authorized to view the form". To my display the form still opens immediately after the msgbox display.
Note that "g_lAccessID" uses a "Setup Global" in the standard module.

 How do I rectify the code? such that the applicable form gives the user only the msgbox and then terminate without opening the target form.

Here is the code I am currently using

   Private Sub Form_Load()
    If g_lAccessID > 3 And IsLoaded("Frm_Switchboard") Then
          MsgBox "You are not authorized to view this details", vbCritical + vbOKOnly, "No authorization"
          DoCmd.Close acForm, "frmMasterControlPanel"
       Exit Sub
    End If
End Sub
ASKER CERTIFIED SOLUTION
Avatar of puppydogbuddy
puppydogbuddy

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of billcute
billcute

ASKER

Thanks, it works.

Regards
Bill