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!

How can I subtract 2 different dates in a form???

Status
Not open for further replies.

hamerlund

Technical User
Mar 8, 2002
1
US
I have a form with the following text boxes. 'Creation Date', 'Scheduled Date', 'Completion Date' and 'Duration'. The form user enters the Creation date, the scheduled date and the completion date. How can I have the Duration textbox fill with the difference of the
Completion date - Scheduled Date. The Duration will have to be in weeks and days. Any help with this will be greatly appreciated.

chris
 
You could use vb .....

Private Sub duration_GotFocus()
duration = DateDiff("d", [completion_date], [scheduled_date])
End Sub

This will calculate the difference between the dates in days - might be a good start for you. I put it in the 'on focus' event for the duration date, but you could put it in the on exit event for the completion date to have it appear directly after the user has updated this field.

For more info, look up datediff in the access help screens.

Amber
 
Try this, make three textboxes;

1st txtbox (to figure the total number of days)
text54
In control source:
=DateDiff("d",[creationdate],[completiondate])

2nd txtbox (to figure the number of weeks)
text55
In control source:
=IIf(Int([text54]) Mod 7=0,[text54]/7,Int([text54]/7))

3rd txtbox (to figure the number of days)
text56
In control source:
=[text54] Mod 7

*The text box numbers 54,55,56 are arbitrary, yours will be different.
You can hide the 1st txtbox the 2nd make label "weeks" and the 3rd make the label "days."
Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top