Add days

ilanray

Member
Local time
Today, 06:17
Joined
Jan 3, 2023
Messages
126
Hi
I have a form with 3 fields. 2 fields in component date and another field with textbox (integer type)
At the first date field I am choosing the date. I would like to calculate the date + text box and insert it to the second date for example
date1: "01-aug-2024'
textbox = 5
i would like to get the date2: 06-aug-2024

Can someone help me with that?
 
Sometimes, just simply adding the number to the date also works.
 
Technically, though you can - and probably should - use DateAdd(), the internal format of date/time fields IS in units of days, and VBA will handle mixed-type operations reasonably. You COULD just add the value from the textbox to a date value.

However, doing so absolutely requires that the date must be in internal date format. For that reason, I recommend DateAdd as well.

 
there should be no need to store the calculation so for your third checkbox in the controlsource put

=[date1]+[textbox] (or use dateadd if you prefer)

if for some reason you need to store the value, you would use vba (probably in the textbox after update event) to populate the underlying field

Secondate=date1+textbox
 
Sometimes, just simply adding the number to the date also works.
Specifically, if you use SomeDate + SomeNumber, the assumption is that SomeNumber = days.

It is ALWAYS better to avoid assumptions. You never know when MS will decide to "fix" an assumption. Also, not everyone is aware of this type of assumption and may make a wrong guess. DateAdd() is unambiguous.
 

Users who are viewing this thread

Back
Top Bottom