Check for file on server during login. If it doesn't exist, shut d

J

JK

I was provided with code that periodically checks for the existence of a file
on one of my network drives. The file name is ChkFile.ozx; if the file name
on the server is changed from ChkFile.ozx to ChkFile.old (or whatever,) my
database displays a message on each users PC and then after a minute shuts
the database down. I do this whenever I need to perform maintenance and/or
updates.

What I’d like to do now is check for the existence of that file during the
login process. If the file name does not exist, then I’d like to display a
message on the users pc and shut the database down which would prevent anyone
from logging in while I’m doing work to the db. I was wondering if someone
would be willing & able to help me out with the code required to do this.

The existing procedure opens a form during login and then hides it; the form
remains open with a timer event that periodically checks for the existence of
the file on the server. I pasted the code below in case it helps.

The form that opens is called frmAppShutDown. The first part of the timer
event simply checks to see if a session is still running at 10:00 PM; if a
session is running at that time, this code shuts the session down so that my
nightly updates will process.

Thanks in advance for any advice you can provide.

Jason

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

'If Now() > TimeValue("22:00") Then
' Application.Quit
'End If

Dim strFileName As String
strFileName = Dir("\\Necfs\DeptFolders\Service db\Version3\chkfile.ozx")
If boolCountDown = False Then
' Do nothing unless the check file is missing.
If strFileName <> "chkfile.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 "frmAppShutDownWarn"
Forms!frmAppShutDownWarn!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


Thanks.
 
J

JK

I added the following code to the timer event of my splash form. It seems to
be working perfectly. Thx so much for your help!

If Len(Dir$("C:\Documents and Settings\jasonk\Desktop\NEC\chkfile.ozx",
vbNormal) & "") > 0 Then
'File exists
Else
'File doesn't exist
MsgBox "This application is unavailable at this time. Your systems
administrator" & vbCrLf & _
"is performing maintenance and or upgrades. Please try again
later.", vbOKOnly, "Attention!"
Application.Quit
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top