Error in Log Each User's Session Guide

G

Guest

In creating a log that will track each user's entering and exiting the
database, I followed the link provided by Gunny (Thanks so much, Gunny!) -

http://www.access.qbuilt.com/html/session_logs.html

And I've implemented all the necessary steps. There's only one "oddity" for
my database - I currently have to use a frm_Welcome_Menu that everyone has to
have opened 1st. What I did was I put an Event Procedure in the event "On
Open" which, I was hoping, would call the frmHidden and then proceed with the
rest of the coding. Below is my "On Open" event procedure.

DoCmd.OpenForm "frmHidden", , , , , acHidden

On Error GoTo ErrHandler

DoCmd.GoToRecord acDataForm, Me.Name, acNewRec
Me!txtUserName.Value = CurrentUser()
Me!txtComputerName.Value = CurrentObjectName()
Me!txtBeginTime.Value = Now()
RunCommand acCmdSaveRecord

Exit Sub

ErrHandler:

MsgBox "Error in Form_Open( ) in" & vbCrLf & _
Me.Name & " form." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & vbCrLf & Err.Description
Err.Clear

End Sub


Then, in the "On Unload" Event Procedure, I have the following -


Private Sub Form_Unload(Cancel As Integer)

On Error GoTo ErrHandler

DoCmd.OpenForm "frmHidden", , , , , acHidden
Me!txtEndTime.Value = Now()

Exit Sub

ErrHandler:

If (Err.Number = 2448) Then
' Ignore, since the form is going into Design View.
Else
MsgBox "Error in Form_Unload( ) in" & vbCrLf & _
Me.Name & " form." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & vbCrLf & Err.Description
End If

Err.Clear

End Sub


I've saved everything and reopened the database - Whenever I try to close
the Welcome Screen (to exit) I get the following error -

Error in Form_Unload() in
frm_Welcome_Screen form.

Error # 2465

Microsoft Access can't find the field "txtEndTime" referred to in your
expression.

I've double checked and ensured that my text control box for this field is
named "txtEndTime" - Promise!

I know this is a simple fix and I'm obviously overlooking something simple;
would anyone mind pointing out my flaw(s)? :)

As always, I greatly appreciate each of your input and assistance on this
matter!

VF
 
G

George Nicholson

Its not entirely clear where you've placed your code. Since you have
deviated from the posted methodolgy (for valid reasons), it's important to
know exactly what is where. (The error message indicates you've confused
Access as well). I was unable to figure out what combination of things would
lead to that error message and only that error message, so this is my best
guess.

It sort of sounds like frmWelcomeMenu contains the 4 bound fields *and* all
the code, not frmHidden?

*If* frmWelcomeMenu has the bound fields and the code then you can try this:
1) Remove all references to frmHidden in your code (and delete the form.
Its not doing anything, is it?)
2) In the OnUnload event:
If Me.Visible Then
' User clicked close
' Cancel the close action, then hide the form instead
Cancel = True
Me.Visible = False
Else
' Since we're already hidden, the app must be closing. Log it.
Me!txtEndTime.Value = Now()
End If

Otherwise, I'd suggest you go back and follow the instructions as posted.

The guiding principles behind the whole idea are:
-Open frmHidden (containing the 4 bound fields and OnOpen & OnUnload
code) when the application starts.
(Note: frmHidden could be opened from the Open event of another
form.)
-In the OnOpen event of *frmHidden*, create & start your log record.
-In the Unload event of *frmHidden* (which will fire when the user exits
the application), log the end time.

You can substitute frmWelcomeMenu (or any form) for frmHidden, but you need
to make sure it stays open as long as the application does (hidden or not)
*and* that it has the 4 bound fields and all the code attached to it.

Since frmHidden is always open, there is no need to open it a 2nd time (as
you are doing). If properly set up, that would create a 2nd "log in" record
as the user is logging out, greatly confusing matters.

HTH,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top