R
red
Hi,
I was wondering if anyone could take a look at my code and see wher
I'm going wrong. I have an access database that I want to only open t
authorized people. I have created a table in the database and include
their names and roles. The database opens to a switchboard and I don
know if this is a problem. Thanks in advance for any help or advice.
Option Compare Database
Option Explicit
Private strCurrentUser As String
Private strRole As String
Dim Result As Variant
Function Startup()
On Error GoTo Err_Startup
Dim DbsCurrent As Database
Dim rsDBUsers As Recordset 'Used to find current user'
role
Dim strCriteria As String 'used to search for user nam
in role table
'Refer current DB
Set DbsCurrent = CurrentDb
'strCurrentUser and strRole are global variables which will stor
the current user name
'and role throughout the current session
strCurrentUser = NetworkUserID()
strRole = "Default"
'Find if user has a role assigned in tblDBUsers
Set rsDBUsers = DbsCurrent.OpenRecordset("tblDBUsers"
dbOpenSnapshot)
Do Until rsDBUsers.EOF
'If user does have a role in tblDBUsers, store that role i
strRole
If rsDBUsers!UserName = strCurrentUser Then
strRole = rsDBUsers!Role
Exit Do
End If
rsDBUsers.MoveNext
Loop
rsDBUsers.Close
DbsCurrent.Close
'Default role is not allowed to access database
If strRole = "Default" Then
MsgBox "You do not have permission to access this database."
vbExclamation, _
"Access Denied"
Application.Quit acQuitSaveAll
End If
Select Case strRole
Case "Administrator":
Application.MenuBar = "mnuBlank"
DoCmd.OpenForm "Switchboard"
Case "User":
Application.MenuBar = "mnuBlank"
DoCmd.OpenForm "Switchboard"
Case "Default":
MsgBox "You do not have permission to access this database."
vbExclamation, _
"Access Denied"
Application.Quit acQuitSaveAll
End Select
Exit_Startup:
DbsCurrent.Close
DoCmd.SetWarnings True
Exit Function
Err_Startup:
MsgBox "Error in 'Startup' function:" & Chr(13) & Chr(10)
Err.Description, _
vbExclamation, "Startup"
Resume Exit_Startup
End Function
Bottom line is its not restricting access to anyone
Thanks,
Re
I was wondering if anyone could take a look at my code and see wher
I'm going wrong. I have an access database that I want to only open t
authorized people. I have created a table in the database and include
their names and roles. The database opens to a switchboard and I don
know if this is a problem. Thanks in advance for any help or advice.
Option Compare Database
Option Explicit
Private strCurrentUser As String
Private strRole As String
Dim Result As Variant
Function Startup()
On Error GoTo Err_Startup
Dim DbsCurrent As Database
Dim rsDBUsers As Recordset 'Used to find current user'
role
Dim strCriteria As String 'used to search for user nam
in role table
'Refer current DB
Set DbsCurrent = CurrentDb
'strCurrentUser and strRole are global variables which will stor
the current user name
'and role throughout the current session
strCurrentUser = NetworkUserID()
strRole = "Default"
'Find if user has a role assigned in tblDBUsers
Set rsDBUsers = DbsCurrent.OpenRecordset("tblDBUsers"
dbOpenSnapshot)
Do Until rsDBUsers.EOF
'If user does have a role in tblDBUsers, store that role i
strRole
If rsDBUsers!UserName = strCurrentUser Then
strRole = rsDBUsers!Role
Exit Do
End If
rsDBUsers.MoveNext
Loop
rsDBUsers.Close
DbsCurrent.Close
'Default role is not allowed to access database
If strRole = "Default" Then
MsgBox "You do not have permission to access this database."
vbExclamation, _
"Access Denied"
Application.Quit acQuitSaveAll
End If
Select Case strRole
Case "Administrator":
Application.MenuBar = "mnuBlank"
DoCmd.OpenForm "Switchboard"
Case "User":
Application.MenuBar = "mnuBlank"
DoCmd.OpenForm "Switchboard"
Case "Default":
MsgBox "You do not have permission to access this database."
vbExclamation, _
"Access Denied"
Application.Quit acQuitSaveAll
End Select
Exit_Startup:
DbsCurrent.Close
DoCmd.SetWarnings True
Exit Function
Err_Startup:
MsgBox "Error in 'Startup' function:" & Chr(13) & Chr(10)
Err.Description, _
vbExclamation, "Startup"
Resume Exit_Startup
End Function
Bottom line is its not restricting access to anyone
Thanks,
Re