Re: Can't put Global Const AppOpenTime = Now in global module
- From: "Neil" <nrgins@xxxxxxxxx>
- Date: Sun, 8 Feb 2009 15:36:57 -0600
"MLH" <CRCI@xxxxxxxxxxxxxx> wrote in message
news:isiuo45tbq6kd4ac3fo0k7u5co3uon5bnk@xxxxxxxxxx
Global Const AppOpenTime = Now
Above statement won't compile. Access
compile error says "Constant expression required"
Why is that?
Now() is not a constant expression, now, is it? A constant is, well,
constant. I.e., it doesn't change. Now() changes.
Is there some property built in to Access in which
the T/D stamp marking the opening of an mdb is
saved? I'm not talking about when Access itself
was launched, but the current database that is
open in Access.
Just create a global variable of type Date to store the value. Then, in
whatever form or switchboard opens when you open your app, set the value to
Now().
If you want to ensure that the value's not changed after you have the
database open, just check for a zero value if in the variable. If it's zero,
then set it; if it's non-zero, then don't. Since the date variable is
formatted for datetime values, you'll have to convert it to double using the
CDbl function to check for zero. Something like:
In global module:
Global dtDBOpen as Date
In your startup form's On Open event:
If CDbl(dtDBOpen) <> 0 Then
dtDBOpen = Now()
End If
Neil
.
- Follow-Ups:
- References:
- Prev by Date: Can't put Global Const AppOpenTime = Now in global module
- Next by Date: Can Access 97 macro be used to set value of global variable?
- Previous by thread: Can't put Global Const AppOpenTime = Now in global module
- Next by thread: Re: Can't put Global Const AppOpenTime = Now in global module
- Index(es):
Relevant Pages
|