• Making a tab invisible (Access 2002 sp1)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Making a tab invisible (Access 2002 sp1)

    Author
    Topic
    #383630

    I have created an application for my office that I am getting ready to distribute. I have enabled username security and want to make certain tabs of a tab control visible or invisible dependent upon the username. I see how I can control entire forms, but not individual tabs. Am I missing something, or is this just not possible?

    Viewing 1 reply thread
    Author
    Replies
    • #654871

      Access doesn’t provide user level security for controls on forms. However, you could write code in the Open or Load event of the form that checks the user name and hides or shows tabs accordingly. This still depends on user level security – if you didn’t have that, everybody would be logged in as ‘Admin’.

    • #654873

      Here’s an example of how to do this using form’s On Open event:

      Private Sub Form_Open(Cancel As Integer)

      With Me
      If IsGroupMember(CurrentUser, “ADMINS”) Then
      .Page2.Visible = True
      End If
      End With

      End Sub

      In example “Page2” is 2nd tab (page) on tab control that only Admins have permission to view. This Page’s visible property should be set to No in design mode. Sub uses IsGroupMember function to determine if current user is member of Admins group:

      Public Function IsGroupMember(strUserName As String, strGroupName As String) As Boolean
      On Error GoTo Err_Handler

      ‘Determine if current user is member of specified group account:
      Dim ws As DAO.Workspace
      Dim usr As DAO.User
      Dim grp As DAO.Group
      Dim ErrMsg As String
      Dim i As Integer

      Set ws = DBEngine.Workspaces(0)
      Set grp = ws.Groups(strGroupName)
      Set usr = ws.Users(strUserName)

      For i = 0 To usr.Groups.Count – 1
      If usr.Groups(i).Name = strGroupName Then
      IsGroupMember = True
      Exit For
      Else
      IsGroupMember = False
      End If
      Next i

      Exit_Function:
      Set ws = Nothing
      Set grp = Nothing
      Set usr = Nothing
      Exit Function
      Err_Handler:
      ErrMsg = “Error No ” & Err.Number & “: ” & Err.Description
      Beep
      MsgBox ErrMsg, vbExclamation, “IS GROUP MEMBER FUNCTION ERROR”
      Resume Exit_Function

      End Function

      Recommend place function in standard code module so can be used anywhere in DB where you need to test user’s group membership. Ensure reference to DAO 3.6 object model is set in References dialog.

      HTH

    Viewing 1 reply thread
    Reply To: Making a tab invisible (Access 2002 sp1)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: