I have a database in which I am using the following module to get the network user ID. I want to avoid having the user having to login again to Access. The database opens with a form that has a field that picks up the network user ID using this module:
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 the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String, strerror 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
'if null then tell the user that no valid log-in was captured
If fOSUserName = "" Then
strerror = "No Valid user id was detected!" & vbCrLf & vbCrLf
strerror = strerror & "Are you logged into Novell?" & vbCrLf
MsgBox strerror, vbCritical, strDbName
End If
End Function
Based on the name in that field, I want to tie that field and compare the name to the entries I have in a table I have created that stipulates the permissions. I have written the following (or a variation of the following) to direct the user to the appropriate switchboard. Since I am not a programmer, I cannot figure out how to tie the two. Have I overcomplicated things?
Can I use the access security in conjunction with the network user ID module and the table instead?
Else
Dim uPass As String
uPass = DLookup("[fldDepartment]", "westek users", "[fldID]=[forms]![frm_splash]![cUser]"
If uPass = "Admin" Then
DoCmd.OpenForm "Switchboard"
ElseIf uPass = "Sales Mgmt" Then
DoCmd.OpenForm "Sales Switchboard"
DoCmd.OpenForm "Marketing Switchboard"
ElseIf uPass = "Materials" Then
DoCmd.OpenForm "Materials Switchboard"
ElseIf uPass = "Fiber" Then
DoCmd.OpenForm "Fiber Switchboard"
ElseIf uPass = "HR" Then
DoCmd.OpenForm "HR Switchboard"
ElseIf uPass = "Facilities" Then
DoCmd.OpenForm "Facilities Switchboard"
ElseIf uPass = "Planning" Then
DoCmd.OpenForm "Planning Switchboard"
ElseIf uPass = "MIS" Then
DoCmd.OpenForm "MIS Switchboard"
ElseIf uPass = "Corporate" Then
DoCmd.OpenForm "Switchboard"
ElseIf uPass = "QC" Then
DoCmd.OpenForm "QC Switchboard"
ElseIf uPass = "Engineering" Then
DoCmd.OpenForm "Engineering Switchboard"
ElseIf uPass = "Accounting" Then
DoCmd.OpenForm "Accounting Switchboard"
ElseIf uPass = "Production" Then
DoCmd.OpenForm "Production Switchboard"
ElseIf uPass = "Operations" Then
DoCmd.OpenForm "Materials Switchboard"
DoCmd.OpenForm "Fiber Switchboard"
DoCmd.OpenForm "Facilities Switchboard"
DoCmd.OpenForm "Planning Switchboard"
DoCmd.OpenForm "QC Switchboard"
DoCmd.OpenForm "Production Switchboard"
DoCmd.OpenForm "Engineering Switchboard"
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 the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String, strerror 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
'if null then tell the user that no valid log-in was captured
If fOSUserName = "" Then
strerror = "No Valid user id was detected!" & vbCrLf & vbCrLf
strerror = strerror & "Are you logged into Novell?" & vbCrLf
MsgBox strerror, vbCritical, strDbName
End If
End Function
Based on the name in that field, I want to tie that field and compare the name to the entries I have in a table I have created that stipulates the permissions. I have written the following (or a variation of the following) to direct the user to the appropriate switchboard. Since I am not a programmer, I cannot figure out how to tie the two. Have I overcomplicated things?
Can I use the access security in conjunction with the network user ID module and the table instead?
Else
Dim uPass As String
uPass = DLookup("[fldDepartment]", "westek users", "[fldID]=[forms]![frm_splash]![cUser]"
If uPass = "Admin" Then
DoCmd.OpenForm "Switchboard"
ElseIf uPass = "Sales Mgmt" Then
DoCmd.OpenForm "Sales Switchboard"
DoCmd.OpenForm "Marketing Switchboard"
ElseIf uPass = "Materials" Then
DoCmd.OpenForm "Materials Switchboard"
ElseIf uPass = "Fiber" Then
DoCmd.OpenForm "Fiber Switchboard"
ElseIf uPass = "HR" Then
DoCmd.OpenForm "HR Switchboard"
ElseIf uPass = "Facilities" Then
DoCmd.OpenForm "Facilities Switchboard"
ElseIf uPass = "Planning" Then
DoCmd.OpenForm "Planning Switchboard"
ElseIf uPass = "MIS" Then
DoCmd.OpenForm "MIS Switchboard"
ElseIf uPass = "Corporate" Then
DoCmd.OpenForm "Switchboard"
ElseIf uPass = "QC" Then
DoCmd.OpenForm "QC Switchboard"
ElseIf uPass = "Engineering" Then
DoCmd.OpenForm "Engineering Switchboard"
ElseIf uPass = "Accounting" Then
DoCmd.OpenForm "Accounting Switchboard"
ElseIf uPass = "Production" Then
DoCmd.OpenForm "Production Switchboard"
ElseIf uPass = "Operations" Then
DoCmd.OpenForm "Materials Switchboard"
DoCmd.OpenForm "Fiber Switchboard"
DoCmd.OpenForm "Facilities Switchboard"
DoCmd.OpenForm "Planning Switchboard"
DoCmd.OpenForm "QC Switchboard"
DoCmd.OpenForm "Production Switchboard"
DoCmd.OpenForm "Engineering Switchboard"