Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Feb 2010
    Denver, CO
    Thanked 0 Times in 0 Posts

    Making a tab invisible (Access 2002 sp1)

    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?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Thanked 31 Times in 31 Posts

    Re: Making a tab invisible (Access 2002 sp1)

    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'.

  3. #3
    Bronze Lounger
    Join Date
    Nov 2001
    Arlington, Virginia, USA
    Thanked 3 Times in 3 Posts

    Re: Making a tab invisible (Access 2002 sp1)

    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
    IsGroupMember = False
    End If
    Next i

    Set ws = Nothing
    Set grp = Nothing
    Set usr = Nothing
    Exit Function
    ErrMsg = "Error No " & Err.Number & ": " & Err.Description
    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.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts