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

Switchboard change depending of user log

Status
Not open for further replies.

yoshi88

Technical User
Mar 18, 2001
48
CA
I have a switchboard but I want to change the menu item if the user is not allowed to open a particular form. I have an admin menu use by only 2 users, that include a lot of specials reports and forms. The rest of the users aren't able to open them (I locked it with the security wizard), but my boss want me not to show this part of the switchboard (the admin). How do I do that. If it's not clear I will try to explain it better (sorry i'm french).

Thanks
 
Hi yoshi88,

The "controls" on your form (buttons, labels...) should have a visible property. Add code to the form's load event to check the admin id and set the appropriate visible properties to false.

Hope this helps
 
could some one give me an example of the cde to do this.
thanks.
 
please help with this code, i have a system due for school soon and ned to know how to do this.

thanks
 
This solution will work if you created your Switchboard using the Switchboard Manager. If you created your own switchboard you will need to modify it to suit what you have created.

If you don't already have something similar, add the following function to a new module:

Code:
Function GetUserGroup()

    Dim db As Database
    Dim TB As Recordset
    Dim ws As Workspace
    Dim strUser As String
    Dim strGroup As String
    Dim strUsql As String
'Set values
Code:
    strUser = CurrentUser()
    Set ws = DBEngine.Workspaces(0)
    Set db = ws.OpenDatabase("FullPathToYourDatabase")
    strUsql = "SELECT UsysUsers.User, UsysUsers.DefaultGroup FROM UsysUsers " _
                & "WHERE (((UsysUsers.User)= '" & strUser & "'));"
    Set TB = db.OpenRecordset(strUsql)
    strGroup = TB("DefaultGroup")
    
    UserGroup = strGroup
End Function

Under the FillOptions procedure of your switchboard, add the following code

'Call function from Utilities module
Code:
	Call GetUserGroup
'Hide option buttons if user is a member of the "YourGroup" (read-only) group.
Code:
	If UserGroup = "YourGroup" Then
		If [SwitchboardID] = 1 Then
			Me("Option" & lblOption1).Visible = False
			Me("OptionLabel" & lblOption1).Visible = False
			Me("Option" & lblOption2).Visible = False
			Me("OptionLabel" & lblOption2).Visible = False
			Me.Command24.Enabled = False
		Else
			Exit Sub
		End If
	End If

The function looks at the UserId and identifies which group the user is a member of. This info is then passed back to the switchboard FillOptions procedure, which then displays or hides the option buttons on the main menu page ([SwitchboardID1]) dependant upon the criteria you specify.

HTH

Lightning
 
i am using a .mdw to store security info so it dosn't like your select statement. is that select statement for no .mdw file?
 
Sorry - I cut that code out of an old db, and forgot that there was a hidden table with the users strored in it.

Try this code:

Function IsUserInGroup(strGroup As String, strUser As String) As Integer
' Returns True if user is in group, False otherwise

Dim ws As Workspace
Dim grp As Group
Dim strUserName As String
Set ws = DBEngine.Workspaces(0)
Set grp = ws.Groups(strGroup)
On Error Resume Next
strUserName = ws.Groups(strGroup).Users(strUser).Name
IsUserInGroup = (Err = 0)
End Function


This should look at the workgroup (part of the workspace) and determine whether the current user is a member of the required group.

Sorry about the mix-up.

Lightning
 
thank you for all you help.
im trying to use that function with your other switchboard code but cant get it to work.
help?
thanks.
 
i got the button on the switchboard to hide depending on what group the user belongs to but there is a space on the switchboard where the button was, i want to get it so the other buttons move up in its place?
help
anyone
please
 
use the object's Top property and change them as you have others disappear...

or you mite consider putting those at the bottom in the first place?? land of milk and Honey
 
Sorry to take so long to answer, but I'm in a way different time zone (it's already Wednesday morning here).

The code simply sets the Visible property to False, so there will always be that gap.
The easiest way to not leave spaces is to set the buttons that will not be available as the lowest option buttons (ie button 8, button 7 and so on).

Another alternative is to put those options on a second menu, with the access button for that menu as option 8 on the main menu, and only set that button's visible property on or off as necessary.

HTH

Lightning
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top