I do not know if this has been asked previously or not if it has I apologize for the repeat.
I am creating an access application that will be utilized by multiple users. I have managed to be able to get the Widows UserID of the individual that is logged on to show in the forms. What I am trying to do now is change it so that in stead of the UserID the full UserName appears in the txtbox. Here is the script I am using:
Public Function fnGetUserID()
Dim User As String * 50
Dim UserID As String
Dim UserName As String
Dim Trash As Long
Dim intCnt As Integer
Dim db As Database
Dim rst As Recordset
Set db = CurrentDb()
Set rst = db.OpenRecordset("tblAccounts", dbOpenDynaset)
' UserID = InputBox("Enter UserID", "LAN Admin User ID")
'get username
Trash = GetUserName(User, 20)
fnGetUserID = UCase(Left(User, InStr(User, Chr(0)) - 1))
'fnGetUserID = Trim(UCase(Left(User, 20 - 1)))
'Password = InputBox("Enter Password", "LAN Admin User ID Password")
rst.FindFirst "(UserID='" & UserID & "' AND UserName= '" & UserName & "')"
'rst.FindFirst "(UserID='" & UserID & "')"
'rst.FindNext "(UserName='" & UserName & "')"
If rst.NoMatch = False Then
MsgBox ("Sorry NO records found")
DoCmd.Close
'Security = "X"
Else
With rst
UserName = Trim(!UserName)
End With
End If
End Function
This script with run and when it gets to, " UserName = Trim(!UserName)" it will actually show the correct full UserName however, when the Function completes it still inserts the UserID into the txtbox. Ant assistance would be greatly appreciated, and if you could explain what I have wrong I would really be gratefull.