Coding Date Question

D

Don

I have a text box (DAYS_GOOD_THROUGH) that is formatted as a Long Integer in
the underlying table with a default value of 30. I have another text box
(GOOD_THROUGH) that is formatted as a Date/Time in the underlying table.

I've written the following code to be executed when the form is open;
however, I keep getting an error.

Me.GOOD_THROUGH = DateAdd("d", Me.DAYS_GOOD_THROUGH, Date)

I want the date that is returned in the text box (GOOD_THROUGH) to be x
amount of days into the future, depending on the value in the text box
DAYS_GOOD_THROUGH.

I'm sure it's something simple that I've not thought about. I'm wondering
if it's due to the way I've set the numerical value of the DAYS_GOOD_THROUGH.

Any help would be appreciated.
 
F

fredg

I have a text box (DAYS_GOOD_THROUGH) that is formatted as a Long Integer in
the underlying table with a default value of 30. I have another text box
(GOOD_THROUGH) that is formatted as a Date/Time in the underlying table.

I've written the following code to be executed when the form is open;
however, I keep getting an error.

Me.GOOD_THROUGH = DateAdd("d", Me.DAYS_GOOD_THROUGH, Date)

I want the date that is returned in the text box (GOOD_THROUGH) to be x
amount of days into the future, depending on the value in the text box
DAYS_GOOD_THROUGH.

I'm sure it's something simple that I've not thought about. I'm wondering
if it's due to the way I've set the numerical value of the DAYS_GOOD_THROUGH.

Any help would be appreciated.


"Keep getting an error" gives us no useful information.
What is the error number and text?

1) Make sure the name of the control is not the same as the name of
any field used in the expression.

2) Are you trying to save a calculated date in your table?
That's an Access No No.
You should delete the [Good_Through] field from your table.

Calculated data need not be saved. Anytime you need to find the
Good_Through date simply calculate it.
In a query ...
GOOD_THROUGH:Date() + [Days_Good_Though]

You can now use the [Good_Through] field anywhere in a form or report.

Or in an UNBOUND control on a form or report:
=Date() + [Days_Good_Through]

But do not store the value in a table.

Note... you could also use your DateAdd function if you wish.
 
R

ruralguy via AccessMonster.com

put a breakpoint on the line by clicking outside the left margin and see what
values you are getting. F8 will single step the code and hovering over the
variables will show their value in a ToolTip.
 

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