I am not sure that this is the right subforum for this topic. I am having some trouble with code. In the following, I am trying to eliminate the lengthy "if-then-else" statement (which does what I need, but needs coding everytime employees change) by comparing the logon name to the names in tblOSLogonName. The function needs to return the full name (2nd column tblOSLogonName).
---------------
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
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If lngX <> 0 Then
strCurrLogon = Left$(strUserName, lngLen - 1)
Else
strCurrLogon = ""
End If
' If strCurrLogon = "icole" Then
' fOSUserName = "Ian Cole"
' ElseIf strCurrLogon = "jmead" Then
' fOSUserName = "John Meade"
' ElseIf strCurrLogon = "dmolloy" Then
' fOSUserName = "Desi Molloy"
' ElseIf strCurrentLogon = "gmatheny" Then
' fOSUserName = "Greg Matheny"
' ElseIf strCurrentLogon = "sjohnstone" Then
' fOSUserName = "Sean Johnstone"
' End If
If strCurrLogon = tblCall!OSLogonName Then
fOSUserName = tblCall!Username
Else
fOSUserName = ""
End If
End Function
-------------------------
Thanks for any help,
Ian
---------------
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
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If lngX <> 0 Then
strCurrLogon = Left$(strUserName, lngLen - 1)
Else
strCurrLogon = ""
End If
' If strCurrLogon = "icole" Then
' fOSUserName = "Ian Cole"
' ElseIf strCurrLogon = "jmead" Then
' fOSUserName = "John Meade"
' ElseIf strCurrLogon = "dmolloy" Then
' fOSUserName = "Desi Molloy"
' ElseIf strCurrentLogon = "gmatheny" Then
' fOSUserName = "Greg Matheny"
' ElseIf strCurrentLogon = "sjohnstone" Then
' fOSUserName = "Sean Johnstone"
' End If
If strCurrLogon = tblCall!OSLogonName Then
fOSUserName = tblCall!Username
Else
fOSUserName = ""
End If
End Function
-------------------------
Thanks for any help,
Ian