Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding user's account group 1

Status
Not open for further replies.

butcher

Programmer
Mar 30, 2001
19
AU
After securing the databse can i find the Account Group the user belongs to using VBA.

e.g.
when a user opens a particular form if they belong to one group they can fill in all fields, if not they can only fill a couple.

butcher
 
This function will tell you if the user is a member of a given group.
Code:
Function UserBelongsToGroup(strGroupName As String, Optional varCurrentUser As Variant) As Boolean

'********************************
'*  Declaration Specifications  *
'********************************

    Dim wsp As Workspace
    Dim grp As Group
    Dim usr As User

    Dim i As Integer
    Dim bolAnswer As Boolean
    
    Dim strCurrentUser As String
    
'****************
'*  Initialize  *
'****************

    On Error GoTo ErrHandler
    
    bolAnswer = False
    
    If (IsMissing(varCurrentUser)) Then
        strCurrentUser = CurrentUser
    Else
        strCurrentUser = CStr(varCurrentUser)
    End If
        
    Set wsp = DBEngine.Workspaces(0)
    Set grp = wsp.Groups(strGroupName)
    Set usr = wsp.Users(strCurrentUser)
    
'******************************************************************
'*  Loop to determine if the User is part of the group specified  *
'******************************************************************

    For i = 0 To grp.Users.Count - 1
         If grp.Users(i).Name = usr.Name Then
              bolAnswer = True
              GoTo ExitProcedure
         End If
    Next i
    
'    wsp.Close
   
'********************
'*  Exit Procedure  *
'********************

ExitProcedure:

    UserBelongsToGroup = bolAnswer

    Exit Function

'****************************
'*  Error Recovery Section  *
'****************************

ErrHandler:
   
    If Err = 3265 Then
        MsgBox UCase(strGroupName) & " isn't a valid group name", vbExclamation

    ElseIf Err = 3029 Then
        MsgBox "The account used to create the workspace does not exist", vbExclamation
         
    Else
        MsgBox Err.Description, vbExclamation
    
    End If
    
    wsp.Close
    GoTo ExitProcedure
 
End Function
 
FancyPrairie
this code worked great

thank you for your knowledge and fast response
butcher
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top