Solved

Shutdown Access Database After Certain Idle Time

Posted on 2014-03-25
20
5,869 Views
Last Modified: 2014-03-26
I did a search on my question but I think that the suggestions are going a bit over the top and based on what I have it shouldnt be that difficult but I cant seem to put everything together.

I am trying to place some code on a front end copy of course. I have a linked table on the front end containing the amount of time I am allowing. I have one form called FRM_MGRWRKSPACE with the OnTimer event set at "1000". This form will always be open no ands ifs about it. I have coded it this way.

I already have a form created that I want to pop up when the time has been exceeded with a "timer" control that I want to use as how much time is left before it will time out. All I need want to do is to place something on the OnTimer event to check the eslapsed time and open the my Shutdown form telling them they have "x" seconds before it will shut down.

What makes what I am trying to do simpler then what has been posted is that the code doesnt have to figure out what the idle time is for the form that they are on. Again I have one form that is opened the entire tiem and that opens subform. Any assistance with this would be great thank you.
0
Comment
Question by:spaced45
  • 10
  • 4
  • 3
  • +2
20 Comments
 
LVL 57
ID: 39955059
Not sure where the question is in there...

The standard technique to detect idle time is this:

http://support.microsoft.com/kb/128814

 which uses screen.activecontrol and screen.activeform

If the user hasn't moved in xxx time, then that's when you'd pop-up your shutdown form and exit after the time elapsed.

Jim.
0
 
LVL 1

Author Comment

by:spaced45
ID: 39955073
question was "How do I Shutdown Access Database After Certain Idle Time". Sorry, I left out the "How Do I". I think the link that you provided is going to be able to do the trick. Thank you. I am going to try it out.
0
 
LVL 75
ID: 39955102
One of these two free apps should work for you (or a combination of the two) ... and I guarantee they both work well. In fact, I built an entire Forced Shutdown Module based on Peters Force Shutdown:

Inactive Shut Down Control
http://www.peterssoftware.com/isd.htm

Force Shut Down
http://www.peterssoftware.com/fsd.htm

mx
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 12

Accepted Solution

by:
jkaios earned 500 total points
ID: 39955121
Try this:


Private Sub Form_Load()
   
   ' start the count down in 3 minutes (60 x 3 = 180)
   Me.Tag = 180
   
   ' interval is every second
   Me.TimerInterval = 1000
   
End Sub

Private Sub Form_Timer()

   On Error Resume Next
   '**********************************
   ' Bail out when count down is zero
   '**********************************
   
   Me.Tag = Val(Me.Tag) - (Me.TimerInterval / 1000)
   
   Me.Caption = "Form will exit in " & Me.Tag & " seconds"
   
   If Val(Me.Tag) <= 0 Then
      DoCmd.Quit
   End If

End Sub

Open in new window

0
 
LVL 1

Author Comment

by:spaced45
ID: 39955126
This is perfect!! Exactly what I was looking for. Hoping to get one last element to this. The example code shows the following:
Sub IdleTimeDetected(ExpiredMinutes)
         Dim Msg As String
         Msg = "No user activity detected in the last "
         Msg = Msg & ExpiredMinutes & " minute(s)!"
         MsgBox Msg, 48
         
End Sub

Open in new window


I can simply add a exit database line as it explains but I would like to add a count down to it of maybe 30 seconds. As I mentioned I have a form I created called Shutdown that I would like to show. To make it easy I thinking that instead of opening the dialog window as the example code does if I can fire off my Shutdown form with a countdown control showing the seconds till shutdown. To make it even simpler OR if the Shutdown form fires up its to late, I would like for it to shutdown.
Not sure if you can do that within the dialog window that comes up in the example code thus not needing my shutdown form to fire up but that would be good also.
0
 
LVL 1

Author Comment

by:spaced45
ID: 39955136
jkaios,

just noticed your post. I am trying your method now.
0
 
LVL 12

Expert Comment

by:jkaios
ID: 39955137
Spaced45, if your Front End app is Access, then just copy and paste the code above and into your "form that is opened the entire time".

If Front End is VB6, simply change Form_Timer() event to YourTimerControl_Timer() where YourTimerControl is the name of the timer control, e.g., Timer1.

Also, you can substitute Me.Tag with a member variable whose scope is accessible thru-out the form.
0
 
LVL 1

Author Comment

by:spaced45
ID: 39955138
jkaios,

Do I set this on the form that I have open the entire time that the user has the app open as I indicated in my initial question?
0
 
LVL 1

Author Comment

by:spaced45
ID: 39955141
you just answered my question
0
 
LVL 12

Expert Comment

by:jkaios
ID: 39955142
...forgot...if VB6, then replace DoCmd.Quit with Unload Me
0
 
LVL 1

Author Comment

by:spaced45
ID: 39955151
testing it out so I set me.tag  = 60. Just noticed the count down int he title bar. I LOVE IT.
I notice though that the count down stops when I dont have the form active. but at this point i can live with that. still testing
0
 
LVL 1

Author Comment

by:spaced45
ID: 39955158
DUDE I LOVE IT. Simple. I can deal with this. I am testing out the "Unload Me" now. Should I see any difference in what the user would see?
0
 
LVL 1

Author Comment

by:spaced45
ID: 39955165
Just to clarify. When I said "dont have the form active" I mean Access active. Noticed it when I was toggling between this site and the app.
0
 
LVL 12

Expert Comment

by:jkaios
ID: 39955169
Are you using Access as your Front End?  If so, then the DoCmd.Quit is the one you're looking for.  The Unload Me statement will just close the form that the code is running on.
0
 
LVL 1

Author Comment

by:spaced45
ID: 39955180
DoCmd.Quit then is what I need. Thank you. I know that having to continue a timer based on either different access forms being open and such require additonal more complex code so I think I am going to leave it at that for now unless you have any suggestions. For now its doing what I want it to do. Might now be within a form an might not be in an in your face way but again it does the trick. Tomorrow, or later today I am going to be posting an additional question dealing with shutdown after checking version number. I have code that is working but having trouble figuring out at what time to run it. Not sure if there is a way for you have the opportunity to answer it but I hope you can assist. Thank you again for all your assistance.
0
 
LVL 1

Author Closing Comment

by:spaced45
ID: 39955183
Simple and direct!
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 39955419
I use a loop to close all of my forms before I execute the forcelogoff, something like:

Dim frm as form
Dim intLoop as integer

If TimeValue(Now()) > > dtForceLogOff Then
    for intLoop = forms.Count - 1 to  0 step -1
        set frm = forms(intLoop)
        frm.Undo   'undoes any unsaved changes
        'frm.AllowClose = true    
        docmd.close acform, frm.Name
   Next
End If

Docmd.Quit

'Allowclose is a form level variable I use to prevent users from closing the main Access window while the application is running.  If you don't use that technique, you will not need that line in the code.

This way, each form is closed before the application is logged off.
0
 
LVL 75
ID: 39956678
Dale ... you are late to the two person party :-)

mx
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 39957003
Joe,

LOL!

I thought this was an extension of a similar thread that I was one of the first responders to.  I had provided a comment on that thread, but had dropped off when someone else took the lead.  When I saw the simple docmd.Quit, with no controlled shutdown of the open forms, I thought I would throw my 2cents in.
0
 
LVL 75
ID: 39957058
Peter's free app takes ALL of that into account - very elegant. He figured it all out.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

827 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question