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

What (VBA) event signals closing the database? 3

Status
Not open for further replies.

bradmaunsell

Programmer
May 8, 2001
156
US
I am trying to save a timestamp for when a user opens the database and when they close the database.

I have been successful with capturing the open but not the close. The close works OK when the user exits using the appropriate close/quit button. However, they often "bail out" from the (many) available Access "X" in the upper right corner of the various application screens. There are many forms, so many "X" opporitunities.

Ideally, I would like to capture both the IN and OUT in a single record. That is, a table having UserName, Tome_IN and Time_OUT. I can use two records if neccessary - one log IN and another for log OUT.

Is there an event to capture the UNLOAD of the database similar to that for UNLOAD of a form? In other words, if I can cature the database UNLOAD, I can either update a single record or append a new record.


Thanks,
Brad
 
Just add a hidden form that opens when the database opens. Give it a close event that does what you want. No matter how you close the database the close event for that form will run.

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
Thanks for the quick response Greg.

Your suggestion works fine with this code.

However, the form will not HIDE. Have I not set HIDE correctly? I right click on the form and set the attribute to "HIDDEN". It is hidden on the forms list but not when running.


'===========================================================
'10/30/2007 Brad Maunsell
'See PUBLIC Variables pubUserName, pubStamp_IN, pubStamp_OUT

Private Sub Form_Load()
pubUserName = GetNetworkUserName
pubStamp_IN = Now()
DoCmd.OpenForm "_MAIN_MENU"
End Sub

Private Sub Form_Unload(Cancel As Integer)
Dim strSQL As String

pubStamp_OUT = Now()

strSQL = "INSERT INTO tblTimeStamps ( UserName, TimeStamp_IN, TimeStamp_OUT )" _
& "VALUES ('" & pubUserName & "', #" & pubStamp_IN & "#, #" & pubStamp_OUT & "#)"

DoCmd.RunSQL (strSQL)
End Sub
'==========================================================
 
bradmaunsell.
You need to open the form as hidden, so when you start your applicaiton and open this form, you'll need to open it like
Code:
docmd.OpenForm("frmHidden",acNormal,"","","",acHidden)

Ideally (IMHO), you'll have a "Splash Screen" type form that opens automatically, opens this hidden form, opens your main menu and does any number of little tasks you may want to do before automatically closing.

hth

Ben

----------------------------------------------
Ben O'Hara
David W. Fenton said:
We could be confused in exactly the same way, but confusion might be like Nulls, and not comparable.
 
How are ya bradmaunsell . . .

Why not give [blue]traingamer[/blue] a well deserved star (pinky) for his/her efforts? . . .

See the link at the bottom of my post! . . .

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
 
Don'tnow what happen but here's pinkys for traingamer & oharab ! . . .

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top