Help with calculating in a control... please

D

DevArrah

I'm having a problem with a control in access 2000.

I have two textboxes on a form called start and length
In the controlSource of a third textbox I have =[start]+Year[length]
The problem is when I enter data into the field I get nutty results.
After literal hours tooling around with I finally tried setting the
controlSource to =Year([length])

Then when I played with the form get these results (result as number
formatted as a general number)

entered into length Result
0 1899
1 1900
2 1900
3 1900

All i want to do is to have a text that automatically adds 'length'
years to the start date. What on god's green earth am I doing wrong? Any
semi-logical reason why I get the results that I do?

I admit this is the first time I'm i've done any extensive fooling
around in access but for the life of me I don't understand why the same
calculation works in a query but not in the control.
 
A

Allen Browne

Assuming that Start is a Date/Time field, and Length is a Number field, use
the DateAdd() function to add the number years to the date, i.e.:
DateAdd("yyyy", [length], [start])

To explain the results you got, internally Access stores date/time values as
a number where the whole number represents the date and the fraction the
time (0.5 = noon (half a day), 0.25 = 6am, etc). They decided that day zero
would be Dec 30 1899. Therefore:
Year(0)
calculates as 1899, and so does Year(1) since that's the next day. Year(2)
is the first day of 1900, so following days up to 366 are all in 1900.

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top