How to build a menu with restrictions

plenilunio

New member
Local time
Today, 01:55
Joined
Oct 16, 2008
Messages
3
Hi, I'd like to build a menu with restrictions depending on the user from Windows Server 2003.

I mean, I have a menu, with some options and submenus. For example, for those who are in the group 'Administrators', they could see the whole menu, but for those who are in the group 'Workers', some options and submenus will be hidden, Is it that possible? Anyone could give some piece of code?

Thanks in advance
 
i use code from access cookbook, which explains how to interrogate the users/groups etc to check membership (standard Access security)

I don't want to post it, in case it infringes copyright, but its easy to follow
 
An alternative to Gemma's suggestion is to create two custom menus then depending on the access rights of the user get access to display the appropriate menu on your main form.

David
 
Okay

Have you got some code to detect the User ID from Windows

How about

Option Compare Database

Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function fOSUserName() As String
'Returns User name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If lngX <> 0 Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = ""
End If

End Function

You might want to get the computer name

Option Compare Database

Private Declare Function apiGetComputerName Lib "kernel32" Alias _
"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function fOSMachineName() As String
'Returns computer name
Dim lngLen As Long, lngX As Long
Dim strCompName As String
lngLen = 16
strCompName = String$(lngLen, 0)
lngX = apiGetComputerName(strCompName, lngLen)
If lngX <> 0 Then
fOSMachineName = Left$(strCompName, lngLen)
Else
fOSMachineName = ""
End If

End Function

Have a form with User and Computer name fields

User field source is =fOSUserName()

Open this with autoexec macro. then open your Opening form over it.

On load event on opening form has event procedure something like

If Not IsNull(DLookup("[Forms]![frm_User_Computer_Names]![txtUser]", "[qry_User_Check_Admin]", "[Forms]![frm_User_Computer_Names]![txtUser]=[qry_User_Check_Admin].[Logon_ID]")) Then
cmd_Sys_Admin.Visible = True
cmd_Commercial.Visible = True
cmd_Processing.Visible = True
cmd_CSM.Visible = True
cmd_MPL.Visible = True
cmd_Quality.Visible = True
cmd_DRP.Visible = True
cmd_Enq.Visible = True
cmd_Stats.Visible = True
cmd_Reports.Visible = True
cmd_MOP.Visible = True
cmd_NPI.Visible = True


End If

Basically I have a query (qry_User_Check_Admin) that extracts records from a table where I keep User ID and their roles and this query only extracts Admin role people

I then swith the visible property of a range of command buttons on teh opening form.

Finally after you go through all the various roles you have one that check for the person existing in your table. In this case they are say Enquiry only users so only the Enquiry command button becomes visible. The Else part of that If statement has Do.Cmd.Quit.

That shuts the database there ejecting everybody who you have not approved to use the database

HTH

L
 

Users who are viewing this thread

Back
Top Bottom