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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

User Log Table 1

Status
Not open for further replies.

GessTechie

Technical User
Jan 24, 2003
10
US
Afternoon All....

I have a User ID table with user ids and passwords. I pass the user id from a gateway screen to another form as a static variable.

Now, I want to update a user log table with the user id from the gateway screen and Date and time the user started the form and the date and time the user saved the record.

I can update the user id, and calculate the start date and time, but the end date and time eludes me.

Any thoughts....
 
and many others.

at best, this is un-reliable -any "crash" will circumvent the posting of the end time. To come close, you would need to trap the application close event. Since I am not aware of such, it doesn't help. Perhaps one of the real GURU's know a bit more, and it would certainly go a ways toward answering an oft lodged inquiry.

You can more or less disable the normal exits and mostly force the exit path through a specific form (swithboard?) and trap the close event of the form to be the (usual) logout process. In that process, you can get the logout time. It does work -IF- you are VERY careful and complete in disabling the various "exits", but it takes extreme efforts to defeat knowledgeable users and even average programmers.

MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Now, what you're saying is you want it recorded when the record is saved, not necessarily when the form is closed, right? Or maybe you want it on exit? Wherever it is up to you.

The answer is much more simple than is explained by the previous post, so don't worry.

To transfer data between forms I have a module sitting over in the modules tab called "Data" which has several public variables which I can set before opening a form, then read from the new form once opened. However you want to transfer data values is up to you.

In any case, in the new form that pops up, you want two global variables in the form's module (say strUserID and dteStartTime). On the On Load event of the form, set the UserID and StartDate to the values you need.

If it's recorded during a save operation (like a save button on the form, in the on_click event), or maybe in the form's on close event, whatever, have a line it it like:

SaveInitials strUserID, dteStartTime, Now()


Then have a function similar to:

Private Sub SaveInitials(UserID As String, StartTime As Date, EndTime As Date)

On Error GoTo ExitSub
Dim rst As Recordset
Set rst = CurrentDb.OpenRecordset("whatevertable", dbOpenDynaset)

rst.AddNew
rst![UserID] = UserID
rst![StartTime] = StartTime
rst![EndTime] = EndTime
rst.Update

ExitSub:

End Sub


You will never have a situation where this code will cause a run-time error due to the simple error handling (like if the form crashes before-hand).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top