469,159 Members | 1,504 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,159 developers. It's quick & easy.

Help with Auto Close VBA

I have code that will pop up a message on someone else computer when I change the trigger. The problem is that it should also do a count down and after 3 minutes close who ever has the database open.

I’m using Code A in the properties for a form “frmSwitchboard” in the “On Timer” and set the Timer Interval to 60000

Im using Code B in form “On Timer” frmAppShutdownWarn Timer Interval to 8000

Everything works except the timer to close the database automatically after 3 minutes

Code A in form frmSwitchboard
Expand|Select|Wrap|Line Numbers
  1.  Option Compare Database
  2.  
  3. Private Sub Form_Open(Cancel As Integer)
  4.  
  5.     ' Set Count Down variable to false
  6.     ' on the initial opening of the form.
  7.     boolCountDown = False
  8.     Dim strFileName As String
  9.     strFileName = Dir("\\us.bank-dns.com\mspmetro\mn157h\blhm\CORRLEND\DataHold\Enabled.db")
  10.     If strFileName <> "Enabled.db" Then
  11.         MsgBox "Database being updated, please try again later."
  12.         Application.Quit acQuitSaveAll
  13.     End If
  14.  
  15. End Sub
  16.  
  17. Private Sub Form_Timer()
  18.  
  19. On Error GoTo Err_Form_Timer
  20.     Dim strFileName As String
  21.     strFileName = Dir("\\us.bank-dns.com\mspmetro\mn157h\blhm\CORRLEND\DataHold\Enabled.db")
  22.     If boolCountDown = False Then
  23.         ' Do nothing unless the check file is missing.
  24.         If strFileName <> "Enabled.db" Then
  25.             ' The check file is not found so
  26.             ' set the count down variable to true and
  27.             ' number of minutes until this session
  28.             ' of Access will be shut down.
  29.             boolCountDown = True
  30.             intCountDownMinutes = 3
  31.             GoTo Warningform
  32.         End If
  33.     Else
  34.         ' Count down variable is true so warn
  35.         ' the user that the application will be shut down
  36.         ' in X number of minutes.  The number of minutes
  37.         ' will be 1 less than the initial value of the
  38.         ' intCountDownMinutes variable because the form timer
  39.         ' event is set to fire every 60 seconds
  40.         intCountDownMinutes = intCountDownMinutes - 1
  41. Warningform:
  42.         DoCmd.OpenForm "frmAppShutDownWarn"
  43.         Forms!frmAppShutDownWarn!txtWarning = "Due to database maintenance this application will automatically shut down in approximately " & intCountDownMinutes & " minute(s).  Please save all work and close the database ASAP."
  44.         If intCountDownMinutes < 1 Then
  45.             ' Shut down Access if the countdown is zero,
  46.             ' saving all work by default.
  47.             Application.Quit acQuitSaveAll
  48.         End If
  49.     End If
  50.  
  51. Exit_Form_Timer:
  52.     Exit Sub
  53.  
  54. Err_Form_Timer:
Code B in form: frmAppShutdownWarn within On Timer
Expand|Select|Wrap|Line Numbers
  1.  Option Compare Database
  2.  
  3. Private Sub Form_Timer()
  4.  
  5. If Text2 = "1" Then
  6.     Me.Detail.BackColor = 65535
  7.     Text2 = "2"
  8. Else
  9.     Me.Detail.BackColor = 255
  10.     Text2 = "1"
  11. End If
  12.  
  13. End Sub
Mar 9 '11 #1
4 3262
TheSmileyCoder
2,321 Expert Mod 2GB
1) Set a code breakpoint at line 44 to try and see whether or not your code gets to that part.
2) Check that your frmAppShutDownWarn is not set to open as a dialog/modal. If it is, your code will effectively Pause until that form is closed again.
Mar 9 '11 #2
How do I do a code breakpoint? and should I change the dialog to none?
Mar 9 '11 #3
TheSmileyCoder
2,321 Expert Mod 2GB
When your standing on the line you want to add a breakpoint to, simply press F9. VBA will stop on that line when your code is running, and to step through your code press F8.

You should change the Modal property to No/False
Mar 9 '11 #4
NeoPa
32,167 Expert Mod 16PB
Check out Debugging in VBA.
Mar 11 '11 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Martin | last post: by
3 posts views Thread by Raffi | last post: by
1 post views Thread by =?Utf-8?B?Q2hyaXM=?= | last post: by
3 posts views Thread by Tyno Gendo | last post: by
1 post views Thread by CARIGAR | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.