424,960 Members | 987 Online
+ 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
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"

 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"

 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 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 SubConclusion : result was correct and I only need to change the value ofthe 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.