Hello everyone! I must have read most of your messages before I think!
I'm new to VBA and having some issues with some code I got :banghead:
I've got some code to check the name of a file on my harddrive, if this file name changes then it opens up a warning form giving 1 minute before access closes. I've done this as I'm about to start using the db that will have about 35 FE users working to 1 BE db, I have written a BAT file to change the name of this .ozx document so that it shuts everyone db down before it runs a backup and compact&repair on all the FE db.
Problem is even after the file name has changed back to what it should be the db still keeps running this code for some reason and the db keeps shutting down....I'm lost so any ideas would be greatly appreciated! My code I have is below:
I'm new to VBA and having some issues with some code I got :banghead:
I've got some code to check the name of a file on my harddrive, if this file name changes then it opens up a warning form giving 1 minute before access closes. I've done this as I'm about to start using the db that will have about 35 FE users working to 1 BE db, I have written a BAT file to change the name of this .ozx document so that it shuts everyone db down before it runs a backup and compact&repair on all the FE db.
Problem is even after the file name has changed back to what it should be the db still keeps running this code for some reason and the db keeps shutting down....I'm lost so any ideas would be greatly appreciated! My code I have is below:
Code:
Option Compare Database
Option Explicit
Dim boolCountDown As Boolean
Dim intCountDownMinutes As Integer
Private Sub Form_Open(Cancel As Integer)
' Set Count Down variable to false
' on the initial opening of the form.
boolCountDown = False
End Sub
Private Sub Form_Timer()
On Error GoTo Err_Form_Timer
Dim strFileName As String
strFileName = Dir("C:\Users\decap\Desktop\French Training Calander\New UK System\test.ozx")
If boolCountDown = False Then
' Do nothing unless the check file is missing.
If strFileName <> "test.ozx" Then
' The check file is not found so
' set the count down variable to true and
' number of minutes until this session
' of Access will be shut down.
boolCountDown = True
intCountDownMinutes = 2
End If
Else
' Count down variable is true so warn
' the user that the application will be shut down
' in X number of minutes. The number of minutes
' will be 1 less than the initial value of the
' intCountDownMinutes variable because the form timer
' event is set to fire every 60 seconds
intCountDownMinutes = intCountDownMinutes - 1
DoCmd.OpenForm "frmAppShutDown"
Forms!frmAppShutDown!txtWarning = "This application will be shut down in approximately " & intCountDownMinutes & " minute(s). Please save all work."
If intCountDownMinutes < 1 Then
' Shut down Access if the countdown is zero,
' saving all work by default.
Application.Quit acQuitSaveAll
End If
End If
Exit_Form_Timer:
Exit Sub
Err_Form_Timer:
Resume Next
End Sub
Last edited by a moderator: