DataAdd Syntax

Ian Wright

Registered User.
Local time
Today, 15:45
Joined
Oct 20, 2007
Messages
28
I am trying to use the DateAdd Function on a form.

I have a field called 1STDATE once entered the form takes you to a ‘NumberOfDays’ field. Upon leaving that I want it to calculate the last date and populate the active box with it. The Field is called '2ndDate'

I am struggling with line
[2ndDate] = DateAdd(D, NumberOfDays , 1STDATE),
where NumberOfDays and 1STDATE are fields.

Any help most gratefully received with thanks,

Ian
 
From MS Access Help:
DateAdd(interval, number, date)

The DateAdd function syntax has these named arguments:

Part Description
interval Required. String expression that is the interval of time you want to add.
number Required. Numeric expression that is the number of intervals you want to add. It can be positive (to get dates in the future) or negative (to get dates in the past).
date Required. Variant (Date) or literal representing date to which the interval is added.
You'll notice the 1st argument is a string value.
 
Hi Rural Guy,

Many thanks for your kind reply, so if I drop the [] it should work?

Also in DateAdd(D, NumberOfDays , 1STDATE), should 1STDATE be in ## if it is a date field?

Ian
 
The interval value has these choices:
Code:
Settings

The interval argument has these settings:

Setting Description 
"yyyy" Year 
"q" Quarter 
"m" Month 
"y" Day of year 
"d" Day 
"w" Weekday 
"ww" Week 
"h" Hour 
"n" Minute 
"s" Second
You'll notice that D is not among the choices.
 
Last edited:
A good point well made, I had looked at that until I was blue in the face.

Many thanks for your help, if only as a proof reader to a crap typist ;O)

Cheers, Ian :)
 
When referring to form/report fields, use the Me. qualifier. It makes compilation more efficient because it tells Access in which library the variable is defined, plus it gives you intellisence.

Me.2ndDate = DateAdd("d", Me.NumberOfDays , Me.1STDATE)
 

Users who are viewing this thread

Back
Top Bottom