Auto Logout of my Database

ok, so I just put a 1 after the empty folder on the network drive
Enabled.db + 1 = Enabled1.db
You can do, that would work. Or you can delete it, or rename it "disabled.db" or rename it anything else.

The load & timer events do a simple search to see if anything exists with that name. It doesn't matter what you do to the file as long as there's no file with that name when you're done.

:edit:

Screen-print attached. I rename this file and everyone gets booted out of database which checks for it.
 

Attachments

  • enabled.JPG
    enabled.JPG
    54.4 KB · Views: 155
Can you please check and let me know if there is correct
 
here are all the pieces
 

Attachments

The database is correct, the file is not.

The code is looking for a file named "enabled.db" in the folder "I:\SHARE\CounterParty Risk\Corey\". The full file path in the code is both the path & file name.
 
I’m sorry to keep asking the same question, but how do I create the file. Would you be able to explain how to make that file or attached it?
 
Create any file. Right click, new, text document (for example).

When it's created it will be in rename mode, call it enabled.db to match your code or call it something else and edit the filename in the code to match the file.

It doesn't have to be a .db file, I chose something unfamiliar to ensure no one tried to run it. My file was a new .txt file renamed and is 0kb as it's completely empty.
 
Hi again CBrighton, I think I have everything setup correctly but my database still is not closing. Let me walk through the steps and let me know if I’m missing something of doing something wrong

1: Created a file on the network drive so that anyone that needs access to the database is able to. I tried this two ways
File “I:\SHARE\CounterParty Risk\Corey\Enabled1.db”

Or tried \\mb.talk-dns.com\mmpmetro\mn157h\blhm\SHARE\CounterParty Risk\Corey\Enabled1.db\enabled.db

The only code I need to change has been changed in the code below.
I have attached a copy of the test database and a print screen showing the folder need.

Code:
Private Sub Form_Open(Cancel As Integer)[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman]    ' Set Count Down variable to false[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]    ' on the initial opening of the form.[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]    boolCountDown = False[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]    Dim strFileName As String[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]    strFileName = Dir("\\mb.talk-dns.com\mmpmetro\mn157h\blhm\SHARE\CounterParty Risk\Corey\Enabled1.db\enabled.db")[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]    If strFileName <> "Enabled.db" Then[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        MsgBox "Database being updated, please try again later."[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        Application.Quit acQuitSaveAll[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]    End If[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman]End Sub[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman]Private Sub Form_Timer()[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman]On Error GoTo Err_Form_Timer[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]    Dim strFileName As String[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]    strFileName = Dir("\\mb.talk-dns.com\mmpmetro\mn157h\blhm\SHARE\CounterParty Risk\Corey\Enabled1.db\enabled.db")[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]    If boolCountDown = False Then[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        ' Do nothing unless the check file is missing.[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        If strFileName <> "Enabled.db" Then[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]            ' The check file is not found so[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]            ' set the count down variable to true and[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]            ' number of minutes until this session[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]            ' of Access will be shut down.[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]            boolCountDown = True[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]            intCountDownMinutes = 2[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]            GoTo Warningform[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        End If[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]    Else[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        ' Count down variable is true so warn[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        ' the user that the application will be shut down[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        ' in X number of minutes.  The number of minutes[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        ' will be 1 less than the initial value of the[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        ' intCountDownMinutes variable because the form timer[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        ' event is set to fire every 60 seconds[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        intCountDownMinutes = intCountDownMinutes - 1[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]Warningform:[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        DoCmd.OpenForm "frmAppShutDownWarn"[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        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."[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        If intCountDownMinutes < 1 Then[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]            ' Shut down Access if the countdown is zero,[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]            ' saving all work by default.[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]            Application.Quit acQuitSaveAll[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        End If[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]    End If[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman]Exit_Form_Timer:[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]    Exit Sub[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman]Err_Form_Timer:[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]    Resume Next[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]End Sub
 

Attachments


Note how these paths are different, the second includes an additional subfolder and the file name is different.


If you give me the full folder path and file name of the file you want to check for I'll confirm whether your code is correct.

Better yet, navigate to the folder/file in windows explorer and provide a screen-shot as that will show the file path & name.

:edit:

I re-read your post and checked the screen-print (but not the database). based on the screen-print and the code quoted in your post it should work.

Keep in mind it's on a 60 second timer so it could take a minute for the warning message to appear. A quicker way to test it is to rename that enabled.db file without having the database open then open the database. See if it lets you access it while that file can't be found.
 
Here is the other address
 

Attachments

I finished work before your last 3 posts.

Do you really want me to look at the 3 attachments or is the last one the most up to date one?
 
Hi CBrighton and thank you for getting back to me. You must be either some type of teacher of have kids. I appreciate your patience with me. Let me know if you prefer me to put the attachments in some other format.

The 3 postings are of my different folder options, more so wondering which one is correct or the best way to set up the auto log out.

Let me reattach them and explain what they are.

The one titled "United" is showing the message I get when I try to open the link in explorer

The next one titled:"United1" shows the folder and the message I get when trying to open the Enabled1.db

The next one titled:"United2" shows where the code placed in the frmSwitchboard form

I didn’t do anything with the On Open, but below is the code I'm using in the On Timer [Event Procedure]

Code:
Private Sub Form_Open(Cancel As Integer)[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman]    ' Set Count Down variable to false[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]    ' on the initial opening of the form.[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]    boolCountDown = False[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]    Dim strFileName As String[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]    strFileName = Dir("D:\Documents and Settings\clvlasa\My Documents\Accessautowork\Enabled1.db")[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]    If strFileName <> "Enabled.db" Then[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        MsgBox "Database being updated, please try again later."[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        Application.Quit acQuitSaveAll[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]    End If[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman]End Sub[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman]Private Sub Form_Timer()[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman]On Error GoTo Err_Form_Timer[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]    Dim strFileName As String[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]    strFileName = Dir("D:\Documents and Settings\clvlasa\My Documents\Accessautowork\Enabled1.db")[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]    If boolCountDown = False Then[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        ' Do nothing unless the check file is missing.[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        If strFileName <> "Enabled.db" Then[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]            ' The check file is not found so[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]            ' set the count down variable to true and[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]            ' number of minutes until this session[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]            ' of Access will be shut down.[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]            boolCountDown = True[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]            intCountDownMinutes = 3[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]            GoTo Warningform[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        End If[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]    Else[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        ' Count down variable is true so warn[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        ' the user that the application will be shut down[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        ' in X number of minutes.  The number of minutes[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        ' will be 1 less than the initial value of the[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        ' intCountDownMinutes variable because the form timer[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        ' event is set to fire every 60 seconds[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        intCountDownMinutes = intCountDownMinutes - 1[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]Warningform:[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        DoCmd.OpenForm "frmAppShutDownWarn"[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        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."[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        If intCountDownMinutes < 1 Then[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]            ' Shut down Access if the countdown is zero,[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]            ' saving all work by default.[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]            Application.Quit acQuitSaveAll[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        End If[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]    End If[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman]Exit_Form_Timer:[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]    Exit Sub[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman]Err_Form_Timer:[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]    Resume Next[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman]End Sub

Do I need to change this
Code:
If strFileName <> "Enabled.db" Then
to
Code:
If strFileName <> "Enabled1.db" Then

Just adding the 1
 

Attachments

I'm trying to test it but having it close on my end, but its not
 
This line says to search for a file called "Enabled1.db" in the folder "D:\Documents and Settings\clvlasa\My Documents\Accessautowork":
Code:
[FONT=Times New Roman]strFileName = Dir("D:\Documents and Settings\clvlasa\My Documents\Accessautowork\Enabled1.db")[/FONT]

This line says that if it has not found a file called "Enabled.db" then do the contents of the If statement:
Code:
[FONT=Times New Roman]If strFileName <> "Enabled.db" Then[/FONT]

The file names differ between the two lines of code, they must be the same.

Change the full file path by removing the 1, this will mean it's always looking for a file called "enabled.db".

Once this is done you should be able to run and use the database normally as long as the file enabled.db exists in the above folder path. If the file doesn't exist (due to deletion or renaming) new users will be told the database is unavailable and the quit command is used and existing users will start getting warning missions and will be sent the quit command 3 minutes after the timer event fires.

There is no need to ever run the .db file you have created. It exists purely for the database to check for its existance. It is basically like a bool datatype, it's either true (exists) or false (does not exist).
 
How would I be able to test this on my end?
The database doesn’t do anything, not even a warning

Code:
Private Sub Form_Open(Cancel As Integer)
    ' Set Count Down variable to false
    ' on the initial opening of the form.
    boolCountDown = False
    Dim strFileName As String
    strFileName = Dir("D:\Documents and Settings\clvlasa\My Documents\Accessautowork\Enabled.db")
    If strFileName <> "Enabled.db" Then
        MsgBox "Database being updated, please try again later."
        Application.Quit acQuitSaveAll
    End If
End Sub
Private Sub Form_Timer()
On Error GoTo Err_Form_Timer
    Dim strFileName As String
    strFileName = Dir("D:\Documents and Settings\clvlasa\My Documents\Accessautowork\Enabled.db")
    If boolCountDown = False Then
        ' Do nothing unless the check file is missing.
        If strFileName <> "Enabled.db" 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 = 3
            GoTo Warningform
        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
Warningform:
        DoCmd.OpenForm "frmAppShutDownWarn"
        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."
        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
 

Attachments

To confirm, you are opening the form which has this code behind it too, not just the database window?
 
No I havn't, Do I open this one frmAppShutdownWarn or this one frmSwitchboard
 

Users who are viewing this thread

Back
Top Bottom