Solved

Shutdown Access Database After Certain Idle Time

Posted on 2014-03-25
20
5,039 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

Expert Comment

by:Jim Dettman (Microsoft MVP/ EE MVE)
Comment Utility
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
Comment Utility
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

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
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
 
LVL 12

Accepted Solution

by:
jkaios earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
jkaios,

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

Expert Comment

by:jkaios
Comment Utility
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
Comment Utility
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
Comment Utility
you just answered my question
0
 
LVL 12

Expert Comment

by:jkaios
Comment Utility
...forgot...if VB6, then replace DoCmd.Quit with Unload Me
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Author Comment

by:spaced45
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Simple and direct!
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
Comment Utility
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

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
Dale ... you are late to the two person party :-)

mx
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
Comment Utility
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

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
Peter's free app takes ALL of that into account - very elegant. He figured it all out.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now