I collected some code to read the lock file and display a message listing the users who are currently using the system.
Trying to read the entire file at one time causes VBA to treat the string as Unicode in the same way as notepad, so I read character by character and filter out non-printable characters.
Sub TestOpenLaccdb() Dim stm As TextStream, fso As FileSystemObject, strLine As String, strChar As String, strArr() As String, nArr As Long, nArrMax As Long, nArrMin As Long Dim strFilename As String, strMessage As String strFilename = CurrentProject.FullName strFilename = Left(strFilename, InStrRev(strFilename, ".")) & "laccdb" Set fso = New FileSystemObject Set stm = fso.OpenTextFile(strFilename, ForReading, False, TristateFalse) 'open the file as a textstream using the filesystem object (add ref to Microsoft Scripting Runtime) While Not stm.AtEndOfStream 'Read through the file one character at a time strChar = stm.Read(1) If Asc(strChar) > 13 And Asc(strChar) < 127 Then 'Filter out the nulls and other non printing characters strLine = strLine & strChar End If Wend strMessage = "Users Logged In: " & vbCrLf 'Debug.Print strLine strArr = Split(strLine, "Admin", , vbTextCompare) 'Because everyone logs in as admin user split using the string "Admin" nArrMax = UBound(strArr) nArrMin = LBound(strArr) For nArr = nArrMin To nArrMax 'Loop through all machine numbers in lock file strArr(nArr) = Trim(strArr(nArr)) 'Strip leading and trailing spaces If Len(strArr(nArr)) > 1 Then 'skip blank value at end 'Because I log when a user opens the database with username and machine name I can look it up in the event log strMessage = strMessage & DLast("EventDescription", "tblEventLog", "[EventDescription] like ""*" & strArr(nArr) & "*""") & vbCrLf End If Next MsgBox strMessage 'let the user know who is logged in stm.Close Set stm = Nothing Set fso = Nothing End Sub
source share