Option Compare Database
Private Sub Form_Load()
Dim dbs As Database
Dim rst As Recordset
Dim strSQL As String
Call InterfaceInitialise
' Check if this is the first time this user / hostname combination has connected
Set dbs = CurrentDb
With dbs
strSQL = "SELECT [tblConnections].* " & _
"FROM [tblConnections] " & _
"WHERE [tblConnections].[UserID] = '" & UCase(cSysInfo.UserName) & "' AND " & _
"[tblConnections].[Hostname] = '" & UCase(cSysInfo.ComputerName) & "'"
Set rst = .OpenRecordset(strSQL)
With rst
Select Case .RecordCount
Case 0 ' First use - add to list and mark as logged on
strSQL = "INSERT INTO [tblConnections] " & _
"SELECT '" & UCase(cSysInfo.UserName) & "' AS UserID, " & _
"'" & UCase(cSysInfo.ComputerName) & "' AS Hostname, " & _
"'" & UCase(cSysInfo.ComputerDomain) & "' AS Domain, " & _
"True AS Connected, " & _
"Now() AS LastLogon"
dbs.Execute strSQL
Case 1 ' Returning user - update list
.Edit
.Fields("Connected") = True
.Fields("LastLogon") = Now
.Update
End Select
End With
End With
Set rst = Nothing
Set dbs = Nothing
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim dbs As Database
Dim rst As Recordset
Dim strSQL As String
Set dbs = CurrentDb
With dbs
strSQL = "SELECT [tblConnections].* " & _
"FROM [tblConnections] " & _
"WHERE [tblConnections].[UserID] = '" & UCase(cSysInfo.UserName) & "' AND " & _
"[tblConnections].[Hostname] = '" & UCase(cSysInfo.ComputerName) & "'"
Set rst = .OpenRecordset(strSQL)
With rst
.Edit
.Fields("Connected") = False
.Fields("LastLogon") = Now
.Update
End With
End With
Set rst = Nothing
Set dbs = Nothing
End Sub