Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dates and Calculated Fields

Status
Not open for further replies.

JerSand

Technical User
Oct 25, 2000
74
US
I thought this would be simple. My form contains, among other fields, short date fields entitled "Expected date of first separation" and "Date of the letter". Each appears simply as the result of dragging the fields from the table on which the form is based onto the form design grid. I would like an unbound text box to display the difference in days between the two dates for each record after the user enters the dates. So I created the unbound text box and entered the folowing code on the control source line: =[Data]![Expected date of first separation]-[Data]![Date of the letter].

I've looked for a Date/Time function that will make this work, but so far have found none and, of course, am getting #Name? as my result.

I'd be grateful for a solution.

Thanks.

JerSand
 
Control sources are a little different than code... About anything that will work in a query will work in a control source as long as it has an equal sign in front of it.

Try

=[Expected date of first separation]- [Date of the letter]

I bet that control source works for you.
 
..and the function you're looking for to give you intervals other than days is

DATEDIFF(/interval/, /start-date/, /end-date/)

where Interval can be

"YYYY" - years
"Q" - Quarters
"M" - Months
"W" - Weeks
"D" - Days
"H" - Hours
"N" - minutes
"S" - Seconds

Haven't the foggiest why the year guy needs all four characters, instead of just one "Y" - but if you use just ONE Y, you will get the number of DAYS between them. Go Figger.

The result is a NUMERIC value of some type, not a date/time guy, don't forget.

JMH
Me? Ambivalent? Well, yes and no....
Another free Access forum:
More Access stuff at
 
While you can NAME controls using words separated by spaces, i.e. "Expected date of first separation" VBA doesn't always allow you to manipulate these controls if you do so; this goes for the code underlying the Properties Box (i.e. the Control Source of the unbound text box).

I created a table and resulting form using the names "ExpectedDateOfFirstSeparation" and "DateOfTheLetter" for the fields/textbox, created an unbound text box and in the Control Source for this text box placed the simple code:
=[Expecteddateoffirstseparation]-[Dateoftheletter]

and it works fine.

Hope this helps.

The Missinglinq "It's got to be the going,
not the getting there that's good!"
-Harry Chapin
 
Many thanks, lameid, WildHare, and missinglinq. Each of your responses was clear, useful, and worked to solve my problem. I'm grateful.

JerSand
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top