Security group

The problem is that you are continuing to check the groups and it should exit your function when you find an admin, not continue or it will inevitably get to the users and then disable for the admin.
 
How to modify the code . Please let me know about that.
 
So following what SOS said, if you go back to post of #11, put the Exit Function statement on each of the case statements, in the respective lines. Ignore the bit where I said you should use Exit For (I editted that out so you don't get confused).
 
Hi , It is working and I pasted the code. Please check whether it is good or not so that i should not have any problems in the future. Thanks A lot to VBAiNet , SOS, Ghudson






Dim UserName As String
Dim curgroup As String
Dim GroupNames(10) As String
Dim ws As Workspace
Dim usr As User
Dim i As Integer
Dim j As Integer
Dim filter As String

UserName = CurrentUser
Set ws = DBEngine.Workspaces(0)
Set usr = ws.Users(UserName)
'Put all groups user is in into an array
For i = 0 To usr.Groups.Count - 1
GroupNames(i) = usr.Groups(i).Name
Next i
'Loop though groups until you get a match and set the curdept variable
For i = LBound(GroupNames) To UBound(GroupNames)
MsgBox ("Group: " & GroupNames(i))
Select Case GroupNames(i)
Case "Admins"
For j = 1 To CommandBars.Count
CommandBars(j).Enabled = True
Next j
Exit Sub
Case "Users"
For j = 1 To CommandBars.Count
CommandBars(j).Enabled = False
Next j
Exit Sub
End Select
Next i
 
[/code]
Dim UserName As String
Dim curgroup As String
Dim GroupNames(10) As String
Dim ws As Workspace
Dim usr As User
Dim i As Integer
Dim j As Integer
Dim filter As String

UserName = CurrentUser
Set ws = DBEngine.Workspaces(0)
Set usr = ws.Users(UserName)

'Put all groups user is in into an array
For i = 0 To usr.Groups.Count - 1
GroupNames(i) = usr.Groups(i).Name
Next i

'Loop though groups until you get a match and set the curdept variable
For i = LBound(GroupNames) To UBound(GroupNames)
Select Case GroupNames(i)
Case "Admins"
For j = 1 To CommandBars.Count
CommandBars(j).Enabled = True
Next j
Exit Sub
Case "Users"
For j = 1 To CommandBars.Count
CommandBars(j).Enabled = False
Next j
End Select
Next i
[/code]
Cleaned it up a little :)
Edit: The tabs act a bit funny :S
 

Users who are viewing this thread

Back
Top Bottom