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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SECURITY ON ONE FIELD

Status
Not open for further replies.

youdaman

Technical User
Dec 26, 2001
66
0
0
US
I have a form that has a tracking number field. I would like the general user to see this field, but only have it updateable by certain users or groups within the database. Any ideas on how I could this would be greatly appreciated. Tks....
 
In the OnOpen event of the form, check to see if the user is a member of the "privileged" group. If not, then disable the control (field). Here's some code that will tell you if the user is a member of a specific group.

To use this function, pass it the name of the group you want to check to see if the CurrentUser is a member of. You do not have to pass the name of the user if the user you want to check is the CurrentUser. If not, then you need to pass the name of the user you want to check. This function returns either True or False.

Example:


txtField.Enabled = UserBelongsToGroup ("PrivilegedGroup")

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
    
    Resume ExitProcedure
 
End Function
 
Fancy, Thanks for the response. I guess I should have explained the whole enchilada. There is a form that all users have access to for inventory. For the general user, the edit button is available for them. The field does need to be updated by a privalege user during an add or an edit. I have been able to hide it for an edit but can't make it reappear if the priv. user clicks the edit button. I hope this clarification helps. I will continue this on Monday. Thanks again!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top