Solved

Restrict form Open failure

Posted on 2006-07-21
2
203 Views
Last Modified: 2010-05-18
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
Comment
Question by:billcute
2 Comments
 
LVL 38

Accepted Solution

by:
puppydogbuddy earned 250 total points
ID: 17158540
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
 
LVL 4

Author Comment

by:billcute
ID: 17159478
Thanks, it works.

Regards
Bill
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now