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