Hide Command button and form from group of users

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bre035
    New Member
    • Sep 2007
    • 42

    #1

    Hide Command button and form from group of users

    Created a database that I want to be maintained and updated by the Department designated Admins. I have an user table that set specific individuals access to Admin and created admin form and functions to add data to tables and new users when needed. However, I only want the admins to see the command button on the form to access the Admin form menu. I have been unable to acheive this.
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Assuming that your Command Button is named Command1, in the Current() Event of your Form:
    Code:
    Private Sub Form_Current()
      Me![Command1].Visible = (CurrentUser = "Admin")
    End Sub

    Comment

    • Bre035
      New Member
      • Sep 2007
      • 42

      #3
      doesn't work. My form is frm_Admin and the command button is Command13. My table that identifies the Admins is tbl_racifid and the field is Admin set to Yes. I have tried Me.Visible statement.

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        Assuming [Admin] is a Yes/No Data Type Field:
        Code:
        Private Sub Form_Current()
          Me![Command13].Visible = DLookUp("[Admin]", "tbl_racifid")
        End Sub
        Assuming [Admin] is a Text Data Type Field:
        Code:
        Private Sub Form_Current()
          Me![Command13].Visible = (DLookUp("[Admin]", "tbl_racifid") = "Yes")
        End Sub

        Comment

        • Bre035
          New Member
          • Sep 2007
          • 42

          #5
          I changed the field type to yes/no and tweek the code a little to read:
          Code:
          Private Sub Form_Open(Cancel As Integer)
          
            If DLookup("admin", "tbl_racfid", "[Racf_ID] = """ & Form_frm_login.Login_RacfID.Value & """") = True Then
             Me.btn_admin.Visible = True
            Else
             Me.btn_admin.Visible = False
            End If
          Last edited by NeoPa; Mar 29 '10, 08:39 PM. Reason: Please use the [CODE] tags provided

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32669

            #6
            Originally posted by ADezii
            Assuming [Admin] is a Yes/No Data Type Field:
            Code:
            Private Sub Form_Current()
              Me![Command13].Visible = DLookUp("[Admin]", "tbl_racifid")
            End Sub
            Assuming [Admin] is a Text Data Type Field:
            Code:
            Private Sub Form_Current()
              Me![Command13].Visible = (DLookUp("[Admin]", "tbl_racifid") = "Yes")
            End Sub
            It's so good to see coders who can handle boolean evaluations properly. So many use the form :
            Code:
            If X = Y Then
             Z = True
            Else
              Z = False
            End If
            instead of the more sensible :
            Code:
            Z = (X = Y)
            The latter (your code) is so much more succinct and to the point, and shows an understanding of what you're dealing with.

            Comment

            • hedges98
              New Member
              • Oct 2009
              • 109

              #7
              Thanks for that comment NeoPa, I realised I have been using the 'less sensible' code for boolean expressions so have gone through my code and altered some of them so it's tidier!

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32669

                #8
                Most people do. There's no shame in starting that way. It's just that when someone (ADezii in this case) shows the way I like to highlight why it's better so people notice and get the point. I'm very pleased to see that you have :)

                Comment

                Working...