Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 212
  • Last Modified:

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
0
billcute
Asked:
billcute
1 Solution
 
puppydogbuddyCommented:
Bill,
move your code to the form open even and add a cancel statement.

Private Sub Form_Open(Cancel As Integer)
    If g_lAccessID > 3 And IsLoaded("Frm_Switchboard") Then
          MsgBox "You are not authorized to view this details", vbCritical + vbOKOnly, "No authorization"
          Cancel = True
          DoCmd.Close acForm, "frmMasterControlPanel"
       Exit Sub
    End If
End Sub
0
 
billcuteAuthor Commented:
Thanks, it works.

Regards
Bill
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now