PDA

View Full Version : Is it possible to check whether the current database is opened exclusively?



prabhafriend
03-21-2011, 06:20 AM
I'm happy if there is a property here instead raising an error and trapping it. Kindly share the solution whatever it is please.

dicepackage
03-24-2011, 05:54 AM
Yes, check the access .ldb lock file by opening it up in Notepad. You will see the computer name and username of every user logged into the database. If more than one is there you will know someone else has access. You can also use this as a method to see who is locking you out.

prabhafriend
03-24-2011, 06:13 AM
Hi Dice. Thanks to your reply. Is there any way to know it programmatically?

dicepackage
03-24-2011, 06:18 AM
Here is a function I built that will return who is logged in rather than if more than one person is in there. You could change this so if Count > 62 it will return locked.

I also have another function called GetEmployeeName which is a function that takes in the computer name and will return a real name. It is optional if you want to include this or not. I like this because computer names are meaningless to me but a real name is helpful.


Private Sub CommandLoggedIn_Click()
On Error GoTo Error_Handler:
Dim LineData As String ' Variable to take in all the data at once
Dim User As String ' Holder for Machine Name in text file
Set cncurrent = CurrentProject.Connection
Open "C:\YOURDATABASE.ldb" For Input As #1 ' Open the table to insert the text file into
Dim Count As Integer
Dim Message As String
Do While Not EOF(1) ' Read a line of data.
Line Input #1, LineData
Do While (Count < Len(LineData))
User = Mid(LineData, Count + 1, 31)
User = Left(User, InStr(User, " ") - 1)
'Computer = Mid(LineData, Count + 32, 31)
Message = Message + User + Chr(9) + GetEmployeeName(User) + vbCrLf
Count = Count + 62
Loop
MsgBox ("Machine" + Chr(9) + Chr(9) + "User" + vbCrLf + Message)
Loop
Close #1
Exit_Procedure:
Exit Sub
Error_Handler:
MsgBox ("Error retrieving records")
End Sub

Function GetEmployeeName(Machine As String) As String
If Machine = "Computer1" then
GetEmployeeName = "John Smith"
End If
End Function