Security group

mothi

Registered User.
Local time
Today, 11:47
Joined
Dec 26, 2009
Messages
111
Hi,
I applied security to my database. It is secured now and the shortcuts are also working fine.

I need to write the code like to disable menu bar, toolbar depending up on the user group rather than on the current user.

I need to enable all the toolbars, if the user belongs to the "Admins" group and Disable all the toolbars if the user belongs to the "Users" group. I tried and am still trying to get that right. So please Help me .
 
Last edited:
Hi VBAINET,
Thanks for the reply , But the code will work for all the users irrespective of Admins and Users.

I need the code to work only for the users belong to "Users" group but should not work to users in"Admins" group so thats why i need to address the group in the code. I would like to know how to do that.
 
Code:
If CurrentUser = "Users" Then

Dim i As Integer
For i = 1 To CommandBars.Count
CommandBars(i).Enabled = False
Next i
 
All tool bars should be visible to all the users in "Admins " group

All tool bars should not be visible to all the users in "Users" group . But it is hiding all the tool bars for both groups . Please Help me

What i figured out is that all the Admin Users belong to both "Admins" and "Users" group so thats why it is hiding all the toolbars for both groups . I need to use If statements. Please help me with that.

'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
'curdept = "Not Found"
'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
'
'Case "Users"
'For j = 1 To CommandBars.Count
'CommandBars(j).Enabled = False
'Next j
'End Select
'Next i
 
Three possibilities:

1. The code (you have tweaked) isn't returning the group of the current user.
2. You didn't properly define what group the current user is in.
3. You haven't logged in as users from the "admins" and "users" groups to test it out.

Consider those three points.
 
Hi VBAINET,
thank you for replying in such short time.

The code is actually working but the thing is
Lets take an example " Admin1" belongs to both "Users" and "Admins" . So thats why it is hiding the toolbars because the user does belong to both groups.

I need to use something like this
If Admin1 belongs to both "Admins" and "Users" group show all tool bars.

If Admin2 belongs to only "Users" group but not to "Admins" Group do not show tool bars. I need to write code some thing like that. Please Help me with that.
 
A Select-Case statement will only take one choice. It is the same as an If-Else statement except that it's written diferently, in other words there's nothing wrong with the SELECT statement. Use a message box to display the group and see if it actually does produce the right group.

Log in as an admin, run the code, see the result in the message box.
Log in as a user, run the code, see the result in the message box.
 
Iam sorry how do you do that. I mean msgbox to show what group u r in
 
'Case "Admins"
'For j = 1 To CommandBars.Count
'CommandBars(j).Enabled = True
Exit Function
'Next j

If you created a function, put that line of code on that line. That should sort your problem out. If it's a sub write Exit Sub.
 
Last edited:
HI VBAinet,

I will get back to you whether it is gonna work or not in an hour because i am working on something else right now. Sorry about that.
 
Mothi, it's LCase(VBA) & UCase(i) & "net"

Haha! Just kidding.

Post back with progress when you're done.
 
Its not working vbaInet ( got it right, )
 
'For i = LBound(GroupNames) To UBound(GroupNames)
Msgbox "Group: " & GroupNames

Put that message box line there and see what value is returned. Log in as an admin, check the value. Then log in as a user, check the value.
 
i mean it is displaying the type mismatch error when i tried to use the msgbox code
 
It is actually returning the correct groups

when i logged in as admin , groups returned were Admins and Users

when i logged in as user , groups returned were Users . So how come the code is hiding toolbars for both of them .
 

Users who are viewing this thread

Back
Top Bottom