Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to check on form load if user is already logged in.. how?

Status
Not open for further replies.

diddydustin

Programmer
Jul 30, 2002
181
US
Hey guys,

I need to check on load of a form if the database is already open by another user. If it is, I need any subsequent tries to open the database to only open it as READ ONLY and tell the user what the Windows username is of the person logged in. How is this possible? What do I need to look into to do this?

Thanks
Dustin
 
I believe that once Access is opened, it is too late to try and switch to 'read-only'. You will need some type of program to front-end your Access application.

The following is some code that will check the 'ldb' file to see who is logged in. Call would be:

If ShowUserRosterMultipleUsers("OTHER") <> "" Then MsgBox "Other Users are present"

Function ShowUserRosterMultipleUsers(RequestType As String) As String
Dim cn As New ADODB.Connection
Dim cn2 As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim i, j As Long
Dim strUserList As String
Dim strComputer As String
Dim chr As String
Dim char As String
' gvstr_Workstation contains this computer name.

10 On Error GoTo Error_Trap

20 cn.Provider = "Microsoft.Jet.OLEDB.4.0"
30 cn.Properties("Jet OLEDB:Database Password") = "123456"
40 cn.Open "Data Source=" & gvstr_ServerPath

50 Set rs = cn.OpenSchema(adSchemaProviderSpecific, , "{947bb102-5d43-11d1-bdbf-00c04fb92675}")

' Output the list of all users in the current database.

60 strUserList = ""
70 While Not rs.EOF
80 strComputer = Trim(rs.Fields("COMPUTER_NAME"))
90 i = Len(strComputer)
100 strComputer = Left(strComputer, i - 1)
110 If RequestType = "ALL" Then
120 strUserList = strUserList & strComputer & vbCrLf
130 ElseIf RequestType = "OTHER" Then
140 If strComputer <> gvstr_Workstation Then
150 strUserList = strUserList & strComputer & vbCrLf
160 End If
170 End If
180 rs.MoveNext
190 Wend
200 rs.Close
210 Set rs = Nothing
220 cn.Close

230 ShowUserRosterMultipleUsers = strUserList ' Return all users or just other than me.

240 PROC_EXIT:
250 Exit Function

260 Error_Trap:
...
End Function


Code: Where the vision is often rudely introduced to reality!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top