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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculate number of days

Status
Not open for further replies.

ghacig

Technical User
Sep 24, 2004
60
US
Hi All,

I have a form with two dates, AdmissionDate and DischargeDate. I have a field for number of days. How can I make the field can filled automatically based on the the admission and discharge dates?

I tried this code for DischargeDate_afterUpdate:

Days = DiscahrgeDate - AdimssionDate

It did not work. Any ideas

George
 
Have you tried the Datediff function?
Me![Date]=DateDiff("d",AdmissionDate,DischargeDate)
Place this on the AfterUpdate Event of both AdmissionDate and DischargeDate.
 
Assuming that you do not have the same spelling errors in your real code then your code should work.
Also, Re-Check the name of the textbox holding the result.

You might also need to consider what happens if the user enters the discharge date first.

 
Thanks for your help. I found the problem. I am using the Microsoft Calendar to fill in the dates. I added the code to the DischargeDate Calendar:

Days = DischargeDate.Value - AdmissionDate.Value

It worked.

Thanks.

George
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top