A
auujxa2 via AccessMonster.com
I have this code which displays in a value list, which user ID is logged into
my database. But I want to show the persons actual name (i.e. John Doe,
instead of BLD2174) I created a table with UserName and UserID as the fields.
UserID has the PC name. I want UserName to show. Here is what I have so far.
Thank you in advance
Private Function WhosOn() As String
On Error GoTo Err_WhosOn
Dim iLDBFile As Integer, iStart As Integer
Dim iLOF As Integer, i As Integer
Dim sPath As String, X As String
Dim sLogStr As String, sLogins As String
Dim sMach As String, sUser As String
Dim rUser As UserRec ' Defined in General
Dim dbCurrent As Database
' Get Path of current database. Should substitute this code
' for an attached table path in a multi-user environment.
Set dbCurrent = DBEngine.Workspaces(0).Databases(0)
sPath = dbCurrent.Name
dbCurrent.Close
' Iterate thru dbCurrent.LDB file for login names.
sPath = Left(sPath, InStr(1, sPath, ".")) + "LDB"
' Test for valid file, else Error
X = Dir(sPath)
iStart = 1
iLDBFile = FreeFile
Open sPath For Binary Access Read Shared As iLDBFile
iLOF = LOF(iLDBFile)
Do While Not EOF(iLDBFile)
Get iLDBFile, , rUser
With rUser
i = 1
sMach = ""
While .bMach(i) <> 0
sMach = sMach & Chr(.bMach(i))
i = i + 1
Wend
i = 1
sUser = ""
While .bUser(i) <> 0
sUser = sUser & Chr(.bUser(i))
i = i + 1
Wend
End With
sLogStr = sMach '& " -- " & sUser
If InStr(sLogins, sLogStr) = 0 Then
sLogins = sLogins & sLogStr & ";"
End If
iStart = iStart + 64 'increment to next record offset
Loop
Close iLDBFile
WhosOn = sLogins
Exit_WhosOn:
Exit Function
Err_WhosOn:
If Err = 68 Then
MsgBox "Couldn't populate the list", 48, "No LDB File"
Else
MsgBox "Error: " & Err.Number & vbCrLf & Err.Description
Close iLDBFile
End If
Resume Exit_WhosOn
End Function
my database. But I want to show the persons actual name (i.e. John Doe,
instead of BLD2174) I created a table with UserName and UserID as the fields.
UserID has the PC name. I want UserName to show. Here is what I have so far.
Thank you in advance
Private Function WhosOn() As String
On Error GoTo Err_WhosOn
Dim iLDBFile As Integer, iStart As Integer
Dim iLOF As Integer, i As Integer
Dim sPath As String, X As String
Dim sLogStr As String, sLogins As String
Dim sMach As String, sUser As String
Dim rUser As UserRec ' Defined in General
Dim dbCurrent As Database
' Get Path of current database. Should substitute this code
' for an attached table path in a multi-user environment.
Set dbCurrent = DBEngine.Workspaces(0).Databases(0)
sPath = dbCurrent.Name
dbCurrent.Close
' Iterate thru dbCurrent.LDB file for login names.
sPath = Left(sPath, InStr(1, sPath, ".")) + "LDB"
' Test for valid file, else Error
X = Dir(sPath)
iStart = 1
iLDBFile = FreeFile
Open sPath For Binary Access Read Shared As iLDBFile
iLOF = LOF(iLDBFile)
Do While Not EOF(iLDBFile)
Get iLDBFile, , rUser
With rUser
i = 1
sMach = ""
While .bMach(i) <> 0
sMach = sMach & Chr(.bMach(i))
i = i + 1
Wend
i = 1
sUser = ""
While .bUser(i) <> 0
sUser = sUser & Chr(.bUser(i))
i = i + 1
Wend
End With
sLogStr = sMach '& " -- " & sUser
If InStr(sLogins, sLogStr) = 0 Then
sLogins = sLogins & sLogStr & ";"
End If
iStart = iStart + 64 'increment to next record offset
Loop
Close iLDBFile
WhosOn = sLogins
Exit_WhosOn:
Exit Function
Err_WhosOn:
If Err = 68 Then
MsgBox "Couldn't populate the list", 48, "No LDB File"
Else
MsgBox "Error: " & Err.Number & vbCrLf & Err.Description
Close iLDBFile
End If
Resume Exit_WhosOn
End Function