Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116

    Form security

    I have set user permissions on forms. So basically if a user has only read access then certain buttons to open a form or delete records will be disabled.

    Now the problem is even if a user does not have access to open a form, he can still go to the navigation pane and double click the form to open it. I have hidden certain forms. Also, I know that I can go to Access options-> Current database and uncheck the "Display navigation pane" option so that the entire pane is hidden. But a user who knows his way around access can still manipulate these settings and view forms/manipulate fields he is not supposed to view.



    Any ideas to disable opening a form through the navigation pane. I am thinking of a message if user double clicks a form. Something like "You do not have permission to view this. Please contact administrator"

  2. #2
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Well, for one I would be locking it down so nobody could get into the navigation pane. But you can add a little trick by using the OpenArgs of the form. In your code to open the form, include the OpenArgs like:
    Code:
    DoCmd.OpenForm "FormNameHere", OpenArgs:= Me.Name
    And then in the OPEN event of the form you can use:
    Code:
    If Me.OpenArgs = vbNullString Then
       "You must open the form from XXXX form"
       DoCmd.Close acForm, Me.Name, acSaveNo
    End If

  3. #3
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116
    Quote Originally Posted by boblarson View Post
    Well, for one I would be locking it down so nobody could get into the navigation pane.
    How do I do that?? And i will try the other method u suggested.

  4. #4
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116
    The method doesn't work? I tried opening the form from the navigation pane and I could. This is what I did. Imagine I have 2 forms called Main and UserInfo. The form UserInfo cannot be seen by all the users, so if he tries opening it through the navigation pane, he should get an error.

    So in the code to open the UserInfo form I wrote this code:

    Code:
     
    DoCmd.OpenForm "UserInfo", OpenArgs:= Me.Name
    and in the open event of the UserInfo form, I used the code:

    Code:
    If Me.OpenArgs = vbNullString Then
      MsgBox "You must open the form from Main form"
       DoCmd.Close acForm, Me.Name, acSaveNo
    End If
    But I can still open the UserInfo form from the navigation pane

  5. #5
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Hi

    I think you need to change this line:
    Code:
     
    DoCmd.OpenForm "UserInfo", OpenArgs:= Me.Name
    to:
    Code:
     
    DoCmd.OpenForm "UserInfo", OpenArgs:= "UserInfo"
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  6. #6
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116
    umm, I am still able to open the form from the navigation pane

  7. #7
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Quote Originally Posted by Bob Fitz View Post
    Hi

    I think you need to change this line:
    Code:
     
    DoCmd.OpenForm "UserInfo", OpenArgs:= Me.Name
    to:
    Code:
     
    DoCmd.OpenForm "UserInfo", OpenArgs:= "UserInfo"
    No, you are incorrect. Me.Name is supposed to remain AS IS - Me.Name because you want the name of the form that is OPENING the form, not the form being opened.

    So, you might need to use this instead:

    Code:
    If Nz(Me.OpenArgs, vbNullString) <> "TheFormNameWhichItShouldbeCalledFrom" Then
    so in the code that calls the form Me.Name is the code you use which passes the name of the form which you were on when you clicked the button to open the second form. The second part is going to go in the open event of the form that you don't want opened unless it matches. So in this case, instead of checking for a null or empty string, we are going to check to see that the OpenArgs matches the form name of the form that SHOULD have opened the form. If not, it will close it.

  8. #8
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116
    Ooooh! This code works. Thanks a ton. It would also be great if you could explain how I can do this:

    Quote Originally Posted by boblarson View Post
    Well, for one I would be locking it down so nobody could get into the navigation pane

  9. #9
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    This should give you a start:

    Locking down Access

    But while that is good, they don't touch on the DISABLE BYPASS KEY which you should also do:
    http://support.microsoft.com/kb/826765

  10. #10
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116
    thanks a lot again! This is exactly what I was looking for. I am gonna mark this thread as solved

  11. #11
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116
    Any idea how I can do that for the login form, that is, disable it from opening in the navigation pane. The login form is the first form that opens and so not sure how to code in that scenario.

  12. #12
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Is there a reason why the login form couldn't be called from the navigation pane? You could add this in the open event of it (to reset them and make them start all over):
    Code:
    Dim i As Integer
    For i = Forms.Count to 0 Step - 1
       If Forms(i).Name <> "LoginFormNameHere" 
          DoCmd.Close acForm, Forms(i).Name, acSaveNo
       End If
    Next
    Then they would be stuck with just the login form open and have to follow it again because it would close every form (we could check for every object too).

  13. #13
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116
    I used your code and I got the error, "Run-time error '2456': The number you used to refer to the form is invalid."

    Code:
    Private Sub Form_Open(Cancel As Integer)
    Dim i As Integer
    For i = Forms.Count To 0 Step -1
    If Forms(i).Name <> "F_Login" Then
    DoCmd.Close acForm, Forms(i).Name, acSaveNo
    End If
    Next
    End Sub

  14. #14
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    When it happens check to see what the value of i is.

  15. #15
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116
    I printed it in the immediate window and I got the value of i as 1. I printed it before the if conditon because the error was in the if condition

    Code:
    Dim i As Integer
    For i = Forms.Count To 0 Step -1
    Debug.Print i
       If Forms(i).Name <> "F_Login" Then
          DoCmd.Close acForm, Forms(i).Name, acSaveNo
       End If
    Next

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Security Help
    By Cheshire101 in forum Security
    Replies: 4
    Last Post: 03-30-2011, 02:43 PM
  2. Access Security
    By Clinton in forum Access
    Replies: 5
    Last Post: 01-06-2011, 08:55 AM
  3. access2007 security?
    By asadi in forum Security
    Replies: 5
    Last Post: 12-21-2010, 04:56 AM
  4. Security..Is there another way?
    By marianne in forum Security
    Replies: 0
    Last Post: 07-19-2009, 07:18 PM
  5. Security Warning
    By mojo53777 in forum Security
    Replies: 0
    Last Post: 11-16-2007, 06:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums