DateAdd function in default value

G

Guest

I have the following 2 fields in a form which are bound to a table with
respective fields.
1. Sent Date
2. Decision Date

User will input the Sent Date and I would like the Decision Date field to
show a default value of 7 days from Sent Date.
I've entered the expression =DateAdd("d",7,[Sent Date]) into the default
value part of the property of Decision Date. However, nothing appears in the
form.

What might be the problem with my expression?
Thanks many.
 
J

JK

Mitch,
Remove the default.
Put the DateAdd in the Control source of you calculated field.
BTY have you thought about:
=[Sent date]+7

will give you the same result

Regards/JK
 
J

John Vinson

I have the following 2 fields in a form which are bound to a table with
respective fields.
1. Sent Date
2. Decision Date

User will input the Sent Date and I would like the Decision Date field to
show a default value of 7 days from Sent Date.
I've entered the expression =DateAdd("d",7,[Sent Date]) into the default
value part of the property of Decision Date. However, nothing appears in the
form.

What might be the problem with my expression?
Thanks many.

I have to disagree with JK here if your desired Decision Date is
intended to be editable (i.e. ordinarily it will be 7 days but for
some rows it might be earlier or later).

The simplest way would be to "push" a value into the textbox in the
AfterUpdate evnt:

Private Sub txtSentDate_AfterUpdate()
If IsNull(Me!txtDecisionDate) Then ' don't stomp on existing data
Me!txtDecisionDate = DateAdd("d", 7, Me!txtSentDate)
End If
End Sub

This assumes textboxes named txtSentDate and txtDecisionDate bound to
the two fields.

John W. Vinson[MVP]
 
L

Larry Linson

John Vinson said:
The simplest way would be to "push" a value into the textbox in the
AfterUpdate evnt:

It might be worth adding that the Default Value only applies to new Records,
and is set when the Form opens to that new Record. Because a factor in
calculating it is another Field on the Form which will not have had a value
entered, the Default value you specified can't be calculated.

However, if it were based on a value that was available, say the built-in
Date() function, the Default value would work for new Records. It wouldn't
work for changing existing records because, as stated above, it only applies
to the creation of new Records.

Larry Linson
Microsoft Access MVP
 

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