Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Mar 2002
    Location
    Ohio, USA
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Auto close a database (Access 2003)

    There is a database on a network drive that 1) opens in exclusive mode. How do I turn that off so others can get in at the same time? 2) I would like to have the database automatically close after... say 1hr. I have tried 2 different timer events and the one will work for seconds or a few minutes, but when I try to move it out to 1hr, it doesn't seem to work. Any suggestion? Here are the 2 sets of code I have tried.

    Private Sub Form_Load()
    NextOperationTime = DateAdd("n", 4, Now)
    End Sub

    Private Sub Form_Timer()
    If Now < NextOperationTime Then
    DoCmd.Quit
    Else
    NextOperationTime = DateAdd("n", 4, Now)
    End If
    End Sub

    AND

    Private Sub Form_Timer()
    user_time = Timer
    max_time = 360000

    If (max_time - user_time) < 1000 Then
    MsgBox "This database is going to close", vbExclamation
    End If

    If (max_time - user_time) < 1 Then
    DoCmd.Quit
    End If
    End Sub

    Can someone help me? Thanks in advance.

    Penny

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Auto close a database (Access 2003)

    About problem 1): make sure that all users have full permissions (read/write/create/delete) to the folder containing the database (and also that the database file (.mdb) hasn't been made read-only).

  3. #3
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Auto close a database (Access 2003)

    The most immediate problem I see is that you are popping a msgbox to announce the database will be closed. Unless there is a user present to tap "OK", it will just sit there.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  4. #4
    2 Star Lounger
    Join Date
    Mar 2004
    Location
    Cincinnati, Ohio, USA
    Posts
    102
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Auto close a database (Access 2003)

    Penny:

    Here's a thought. First, let's leave the issue of turning off the exclusive mode for another post.

    I think your variable "NextOperationTime" is either undeclared or has a scope problem.

    In the declarations section of your form, put the following

    Option Explicit
    Public dtNextOperationTime as Date


    In the Form_Load event, I'd put the following

    dtNextOperationTime = VBA.DateAdd("h",1,VBA.Now())

    Just for grins, try the following:

    Debug.Print "dtNextOperationTime ="dtNextOperationTime

    Check your immediate window to verify that dtNextOperationTime is set properly

    In the form_timer event, it looks like the logic might be backwards.

    If now is less than dtNextOperationTime, you should not quit.

    Try this:

    <pre>Private Sub Form_Timer()

    If VBA.Now() < dtNextOperationTime Then
    'Do not quit -- This is a comment
    Else
    Docmd.Quit
    End If
    End Sub
    </pre>


  5. #5
    New Lounger
    Join Date
    Mar 2002
    Location
    Ohio, USA
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Auto close a database (Access 2003)

    Thanks Mike, it did work at exactly 1 hour, just like I wanted. I did have the "NextOperationTime" declared, but must have done something wrong. Thanks again. Penny

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •