By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,960 Members | 987 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,960 IT Pros & Developers. It's quick & easy.

Accessing a constant

P: n/a
I'm sure this is insanely obvious... but i can't figure it out.

I have a db that organises applications for an event. Included in the
applicant information is their date of birth. On a form or report i can
calculate and display their current age (=(DateDiff("d",[DOB],Date()))/365)
and also their age at the time (=(DateDiff("d",[DOB],"28/07/07"))/365) of
the event.

As you can see i'm using a hardcoded date for the event date so i have to
change the expression all over the place. How can i set this date in one
location and reference it throughout the application?

cheers,

/mark

Oct 30 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Mark,
You could calculate theese ages in a query and use it as a source for forms
and/or reports.

"Mark Weedon" <ma**@markweedon.co.uka écrit dans le message de news:
hO********************@pipex.net...
I'm sure this is insanely obvious... but i can't figure it out.

I have a db that organises applications for an event. Included in the
applicant information is their date of birth. On a form or report i can
calculate and display their current age
(=(DateDiff("d",[DOB],Date()))/365)
and also their age at the time (=(DateDiff("d",[DOB],"28/07/07"))/365) of
the event.

As you can see i'm using a hardcoded date for the event date so i have to
change the expression all over the place. How can i set this date in one
location and reference it throughout the application?

cheers,

/mark



Oct 30 '06 #2

P: n/a

Hello Mark,

I tried following :

a) create a module where I create following constant :

Public Const cEventDate As Date = "28/07/07"

b) create a testform with following code in its on-open event :

Private Sub Form_Open(Cancel As Integer)
MsgBox (DateDiff("d", "28/09/06", cEventDate))
End Sub

Conclusion : result was correct and I only need to change the value of
the constant
whenever there's a new event date.

Hope this works for you...

Regards,
Rudi.

Oct 30 '06 #3

P: n/a
Rudi,

Right, but in order to use that constant in reports, you'd have to have
a public function:

Public Function fEventDate() as Date
fEventDate = cEventDate
End Function
Then, you could use

=(DateDiff("d",[DOB],fEventDate()/365)

Chris Nebinger
Rudi wrote:
Hello Mark,

I tried following :

a) create a module where I create following constant :

Public Const cEventDate As Date = "28/07/07"

b) create a testform with following code in its on-open event :

Private Sub Form_Open(Cancel As Integer)
MsgBox (DateDiff("d", "28/09/06", cEventDate))
End Sub

Conclusion : result was correct and I only need to change the value of
the constant
whenever there's a new event date.

Hope this works for you...

Regards,
Rudi.
Oct 30 '06 #4

P: n/a
"Mark Weedon" <ma**@markweedon.co.ukwrote in
news:hO********************@pipex.net:
I have a db that organises applications for an event. Included in the
applicant information is their date of birth. On a form or report i
can calculate and display their current age
(=(DateDiff("d",[DOB],Date()))/365) and also their age at the time
(=(DateDiff("d",[DOB],"28/07/07"))/365) of the event.
If it's important that the age be accurate to the day then I'd suggest
Googling this group for an accurate Age function. It's surprising how much
ill will can be generated by being a day or two out.

If on 28/Jul/07 you use your function to tell a woman born on 30/Jul/1977
that she's over thirty, then you may need to take steps to avoid a problem.
Big, fast steps.

Cheers,
Alan Carpenter
Oct 31 '06 #5

P: n/a
Chris,
thanks for pointing that out. I was too hasty, but then again,
according to Alan's justified remark I might have reason enough to! :-)

Thanks guys.
Rudi.

Oct 31 '06 #6

P: n/a
So... why when i create a form... have a text box can't i set the value of
that text box...

where do i put the expression =(DateDiff("d",[DOB],cEventDate()/365))?
Control Source??

Cheers,

/mark
<ch************@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
Rudi,

Right, but in order to use that constant in reports, you'd have to have
a public function:

Public Function fEventDate() as Date
fEventDate = cEventDate
End Function
Then, you could use

=(DateDiff("d",[DOB],fEventDate()/365)

Chris Nebinger
Rudi wrote:
>Hello Mark,

I tried following :

a) create a module where I create following constant :

Public Const cEventDate As Date = "28/07/07"

b) create a testform with following code in its on-open event :

Private Sub Form_Open(Cancel As Integer)
MsgBox (DateDiff("d", "28/09/06", cEventDate))
End Sub

Conclusion : result was correct and I only need to change the value of
the constant
whenever there's a new event date.

Hope this works for you...

Regards,
Rudi.

Nov 1 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.