Altering Tables in VBA

Finchy

Registered User.
Local time
Today, 19:03
Joined
Jul 15, 2010
Messages
14
Hello All,

I am building my first database for a friends salon buisness. He has requested that the database log's everybody logging in and out and the times so he can monitor this for irregularities.

I have this code to the Log In button on the main form.

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblloginlog", dbOpenDynaset)
With rst

.AddNew
![Users Name] = Me.firstname

![Time Logged In] = Now()

.Update

End With

Which works fine!

I have several Log Out buttons, on each of these buttons there is the following code:

Set rst = dbs.OpenRecordset("tblloginlog", dbOpenDynaset)
With rst

.AddNew
![Time Logged Out] = Now()
.Update
End With


Again this works fine.

The problem I have is that when a user logs in and logs out it creates 2 entries in the table.

Obvioulsy as you may have worked out this is always going to happen with the above method!

I would like to combine the logging in and logging out times so I can display it better on a form.

Does anybody have any tips, perhaps I am going about things the wrong way? Is there a line of code which has the ability to move my logging out time to an existing entry?

Any help would be very appreciated.

John (Finchy) Finch
 
At logout you could open the recordset as a query that returns a single record where the logout time for that user was Null. Then update that field to the current time.

You would need to cover the possiblity of missing logins or logouts and warn immediately that a record was incomplete.
 

Users who are viewing this thread

Back
Top Bottom