Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old February 1st, 2005, 12:04 PM
ru1 ru1 is offline
Authorized User
 
Join Date: Feb 2005
Location: Detroit, MI, USA.
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default Closing an Access Database

Hi everyone. This is my first post and I hope it is a good one. I have an Access database that needs to be closed at the end of the day so I can copy a fresh version of it to the location where it may be open. Is there a way that through VB code I can check and say ok, it is 3:00 am in the morning so I would like to close the database?

Remember, nobody will be here, I just want to wake the database up at 3:00 am if it is open, close it. This needs to all be done with vb code?

Any suggestions would be appreciated...

Thanks.
  #2 (permalink)  
Old February 1st, 2005, 12:41 PM
Friend of Wrox
 
Join Date: Jan 2005
Location: , , United Kingdom.
Posts: 100
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Ru1

You could create a Hidden form that opens on startup in an autoexec or in your startup forms load event, Apply the following sub to the OnTimer event. This is a very simple way to close the database at a set time.

Private Sub Form_Timer()
    Dim dtCloseTime As Date
    Dim dtCurTime As Date

    dtCloseTime = Format(#3:00:00 AM#, "hh:mm")
    dtCurTime = Format(Time(), "hh:mm")

    If dtCurTime = dtCloseTime Then
        Application.Quit
    End If

End Sub

Set the timer interval to 60000 (60 seconds) Then every 60 seconds the database checks the time to see if it is time to say goodnight!

HTH

Jp
  #3 (permalink)  
Old February 1st, 2005, 01:18 PM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

I might add the caveat that instead of:

If dtCurTime = dtCloseTime Then

use:

If dtCurTime > dtCloseTime Then

Since in the first line dtCurTime would have to exactly equal dtCloseTime, which there is very little chance of happening. In the second line, the next time the script runs After 3:00:00 AM, the app will shut down.

mmcdonal
  #4 (permalink)  
Old February 1st, 2005, 01:21 PM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Actually, I missed the hh:mm format, which would do the trick.

mmcdonal
  #5 (permalink)  
Old February 1st, 2005, 01:23 PM
Friend of Wrox
 
Join Date: Jan 2005
Location: , , United Kingdom.
Posts: 100
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ah, Well Spotted!

Wouldn't the Formatting take care of the time factor as it evaluates it in minutes?? as the sub runs every minute it will always catch the time??


Similar Threads
Thread Thread Starter Forum Replies Last Post
Closing MS Access at a set time firefighter2045 Access VBA 5 October 29th, 2007 12:15 PM
Opening & Closing Database connections pauliehaha Classic ASP Databases 4 December 18th, 2006 08:50 AM
Remote access to an Access Project Database bright_mulenga Access 0 February 9th, 2006 10:51 AM
Closing Database Connection chrscote Classic ASP Databases 3 June 2nd, 2005 08:29 AM
Access issues with ASP and a MS Access Database rj_conceptsnrec.com Classic ASP Databases 2 May 19th, 2005 12:44 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.