Constants in Access 2000

D

Del

My database has some lengthy code in the startup that only needs to be done
once a day. If I can store the date when the database is opened the first
time each day then I can bypass the startup code for subsequent startups that
day. Is there anyway to set a constant equal to Date() with code?
 
G

George Nicholson

Not sure what good a constant will do you since it won't persist between
startups (nor would UserA's constant be "visible" to UserB on startup).

I think you need to save the MostRecentStartup value in a table accessible
to all users, and then check to see if it has todays date. If not, do
whatever you need to do each day (which now includes updating the stored
value).

Something to consider regardless of whether you use a constant or not:
What happens if 2 users log in at the same time? What if both see yesterdays
date and both try to run your daily code at the same time? If that would
cause a problem then you might need to store 2 values: one for
LastDailyCodeStart and one for LastDailyCodeEnd. Consider:

(assumes you have retrieved LastDailyCodeStart and End from a table)

If dtmLastDailyCodeStart <> Date()
' Code hasn't run today
'Update the stored LastDailyCodeStart to Date()
'Run your Code
'Update the stored LastDailyCodeEnd to Date()
Else
' Code has run today
If dtmLastDailyCodeEnd <>Date()
' DailyCode is still running. Advise user and exit.
MsgBox "Access denied. Files are being updated. Please try again in
a minute."
Application.Quit
Else
'Do nothing. Daily code has run to completion today.
End If
End If
 
T

tedmi

Create a table with one field of type Date. Initialize it to yesterday's date.
The first thing your start-up code should do is run a query to get the value
from that table. If the value is today's date, exit. If not, the start-up
code runs in its entirety, and at the end updates the date table to Today().
 

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

Similar Threads


Top