Results 1 to 10 of 10

Hide command button on form from certain users

  1. #1
    Delfina is offline Advanced Beginner
    Windows 10 Access 2007
    Join Date
    Jan 2019
    Location
    Bartlesville OK
    Posts
    44

    Hide command button on form from certain users

    Could someone please tell me what I am doing wrong in the following statement?

  2. #2
    Delfina is offline Advanced Beginner
    Windows 10 Access 2007
    Join Date
    Jan 2019
    Location
    Bartlesville OK
    Posts
    44
    Private Sub Form_Load()
    If UserLevel = "admin" Then
    With Forms("Menu")
    Command2.Visible = True
    Command2.Visible = True
    'or
    If UserLevel = "Editor" Then
    With Forms("Menu")
    Command2.Visible = True
    Command2.Visible = True
    'or
    If UserLevel = "User" Then
    With Forms("Menu")
    Command2.Visible = False
    Command2.Visible = False
    End Sub

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    13,496
    What is UserLevel?
    Why are there duplicate assignments for Command2 in each option?

    What exactly do you intend this code to do?

    I recommend this Steve Bishop video for Login ideas.
    And this one for Managing User Access

  4. #4
    Delfina is offline Advanced Beginner
    Windows 10 Access 2007
    Join Date
    Jan 2019
    Location
    Bartlesville OK
    Posts
    44
    Thank you. I will look at those and let you know how it works.

  5. #5
    isladogs's Avatar
    isladogs is offline Voodoo Is Practised
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    2,983
    I'm sorry to tell you but almost everything is wrong with your code
    1. 3 With ... and no End With
    2. 3x If ... and no End If
    3. Command2.Visible lines duplicated

    The code for Admin and Editor is identical so that can also be simplified

    Code:
    Private Sub Form_Load()
    If UserLevel = "admin" Or UserLevel = "Editor" Then
       Forms!Menu.Command2.Visible = True
    ElseIf UserLevel = "User" Then
       Forms!Menu.Command2.Visible = False
    End If
    End Sub
    BUT assuming command2 is on the same form as this code, use Me. syntax

    Code:
    Private Sub Form_Load()
    If UserLevel = "admin" Or UserLevel = "Editor" Then
       Me.Command2.Visible = True
    ElseIf UserLevel = "User" Then
       Me.Command2.Visible = False
    End If
    End Sub
    Or simpler still

    Code:
    Private Sub Form_Load()
    
       Me.Command2.Visible = True
       If UserLevel = "User" Then Me.Command2.Visible = False
    
    End Sub
    Last edited by isladogs; 02-09-2019 at 05:05 PM.
    Colin (Mendip Data Systems), previously known as ridders52 : Website, email
    If this has helped, please click the star button and leave a comment

  6. #6
    Delfina is offline Advanced Beginner
    Windows 10 Access 2007
    Join Date
    Jan 2019
    Location
    Bartlesville OK
    Posts
    44
    That is awesome. It was so simple. Thank you very much. It is working great now.

  7. #7
    isladogs's Avatar
    isladogs is offline Voodoo Is Practised
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    2,983
    You're welcome. Just out of interest, which version did you use?
    Colin (Mendip Data Systems), previously known as ridders52 : Website, email
    If this has helped, please click the star button and leave a comment

  8. #8
    Delfina is offline Advanced Beginner
    Windows 10 Access 2007
    Join Date
    Jan 2019
    Location
    Bartlesville OK
    Posts
    44
    The last one. I already had user security set up and an audit trail that was working fine. I just didn't like having an admin page, editor page and user page. Now I can just have one called menu and hide the command buttons based on their security level. Now I am going to look into disabling the quick access commands so no one can tamper with anything. I have it working in 2007 just great. But I am building it in 2007 and then migrating to 2016. And the privacy option still shows up even with a custom ribbon. But I still need to be able to access everything even after disabling the shift key. I probably need to post this in a different thread though.

  9. #9
    isladogs's Avatar
    isladogs is offline Voodoo Is Practised
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    2,983
    For some reason, removing parts/all of the File menu has come up repeatedly in the past week or so.
    See this link https://www.access-programmers.co.uk...d.php?t=303653 for more information and the other 3 links in that thread that I listed.

    You might also find this article on my website useful: http://www.mendipdatasystems.co.uk/i...ity/4594461803

    EDIT:
    AFAIK the only way to disable the quick access toolbar is to remove it completely. To do that, you have to remove the ribbon completely.
    I would be great if you could just remove the customise dropdown on the QAT but I believe that can't be done
    Colin (Mendip Data Systems), previously known as ridders52 : Website, email
    If this has helped, please click the star button and leave a comment

  10. #10
    Delfina is offline Advanced Beginner
    Windows 10 Access 2007
    Join Date
    Jan 2019
    Location
    Bartlesville OK
    Posts
    44
    That is awesome. Thank you. I will let you know how it works out.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 10-27-2016, 09:51 PM
  2. Hide Button in sub form view
    By Derrick T. Davidson in forum Programming
    Replies: 5
    Last Post: 01-27-2016, 06:13 AM
  3. Replies: 3
    Last Post: 08-04-2013, 06:11 AM
  4. Replies: 2
    Last Post: 06-06-2012, 09:53 AM
  5. Replies: 1
    Last Post: 07-27-2010, 01:27 PM

Posting Permissions

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