Re: Can't put Global Const AppOpenTime = Now in global module




"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


.



Relevant Pages

  • Re: De-referencing NULL
    ... pointer performs the same action as deferencing a pointer containing ... address zero. ... due to the special-case rule that C uses to define ... constant expression or not, ...
    (comp.lang.c)
  • Re: segfault on strtok
    ... > integer which is zero is a null pointer constant if cast to void *. ... > a pointer type. ... An integer constant expression with the value 0, ...
    (comp.lang.c)
  • Re: Compiler error or? Microsoft VC++ v6.0
    ... The rule says that a null pointer constant is a ... > constant expression evaluating to zero. ... > constant qualifies as a constant expression. ...
    (microsoft.public.vc.language)
  • Re: Compiler error or? Microsoft VC++ v6.0
    ... constant expression evaluating to zero. ... constant qualifies as a constant expression. ...
    (microsoft.public.vc.language)