Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #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.
Reply With Quote
  #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
Reply With Quote
  #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
Reply With Quote
  #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
Reply With Quote
  #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??
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 09:07 AM.


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