J
Jan T
I am using Access 2010 (accdb) and ADO with VBA. Trying to write code
to log whenever a person
is loged in or out of the program. I am using the following table for
loging this:
ID (autonumber)
User (text)
LogedIn (date/time)
LogedOut (date/time)
When open the database, an macro are adding a new record and fills out
all fields except
the LogedOut field.
When closing the program, the code should look for a record with
UserName so and so and that still have no LogedOut field data in it.
That is, LogedOut is Null (date/time field), right? When found, the
macro should fill in the right date and time (using Now() function).
However, the code never adds date/time to the empty LogedOut field?
and I just don't see why?
It looks like it does not recognise that LogedOut = Null? and therefor
do not add data to the empty field.
Here is the code I use:
Sub LogOut()
Dim rst As ADODB.Recordset
Dim strCriteria As String
Set rst = New ADODB.Recordset
strCriteria = ReturnUserName
rst.Open "tblLogedIn", CurrentProject.Connection, _
adOpenDynamic, adLockOptimistic
With rst
.MoveFirst
Do While Not rst.EOF
If ![User] = strCriteria Then
If ![LogedOut] = Null Then ' /// the code never
returns true here, why?
![LogedOut] = Now()
.Update
End If
End If
.MoveNext
Loop
End With
rst.Close
Set rst = Nothing
Set cnn = Nothing
End Sub
Any help is very much appreciated.
Regards Jan T
to log whenever a person
is loged in or out of the program. I am using the following table for
loging this:
ID (autonumber)
User (text)
LogedIn (date/time)
LogedOut (date/time)
When open the database, an macro are adding a new record and fills out
all fields except
the LogedOut field.
When closing the program, the code should look for a record with
UserName so and so and that still have no LogedOut field data in it.
That is, LogedOut is Null (date/time field), right? When found, the
macro should fill in the right date and time (using Now() function).
However, the code never adds date/time to the empty LogedOut field?
and I just don't see why?
It looks like it does not recognise that LogedOut = Null? and therefor
do not add data to the empty field.
Here is the code I use:
Sub LogOut()
Dim rst As ADODB.Recordset
Dim strCriteria As String
Set rst = New ADODB.Recordset
strCriteria = ReturnUserName
rst.Open "tblLogedIn", CurrentProject.Connection, _
adOpenDynamic, adLockOptimistic
With rst
.MoveFirst
Do While Not rst.EOF
If ![User] = strCriteria Then
If ![LogedOut] = Null Then ' /// the code never
returns true here, why?
![LogedOut] = Now()
.Update
End If
End If
.MoveNext
Loop
End With
rst.Close
Set rst = Nothing
Set cnn = Nothing
End Sub
Any help is very much appreciated.
Regards Jan T