hiding a button on a form

gbanks

Registered User.
Local time
Today, 23:01
Joined
Feb 9, 2000
Messages
161
Is there a way to hide a button on a form if the current user does not have admin right set in security or is a member of a certain group in the db's security. I have a button I want to leave on a form for only users with admin rights or a member of a group called exportsecure. I've set the security in the db. Is this possible? Thanks very much..
 
gbanks said:
Is there a way to hide a button on a form if the current user does not have admin right set in security or is a member of a certain group in the db's security. I have a button I want to leave on a form for only users with admin rights or a member of a group called exportsecure. I've set the security in the db. Is this possible? Thanks very much..

There may be an easier way, but here's what I do.
Create a module and paste the following code into it:
Function CheckGroup(UserName As String, GroupName As String)
On Error GoTo err_CheckGroup

Dim wsp As Workspace, i As Integer
Dim usr As User
Dim blnFound As Boolean
Set wsp = DBEngine.Workspaces(0)
Set usr = wsp.Users(UserName)
blnFound = False
For i = 0 To usr.Groups.Count - 1
If usr.Groups(i).NAME = GroupName Then
blnFound = True
Exit For
End If
Next i
'wsp.Close
CheckGroup = blnFound
Exit Function

err_CheckGroup:
MsgBox Err.Description
Exit Function

End Function

Then save the module.
On your form, set the Visible property of your button to No.
In the On Load event of your form, insert the following code:
If CheckGroup(CurrentUser, "exportsecure") Then
Me.ButtonName.Visible = True
Else
Me.ButtonName.Visible = False
end if

Where ButtonName is the name of your button. This will make the button visible to only those members of your exportsecure group.
 

Users who are viewing this thread

Back
Top Bottom