Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Write DateAdd() info into a table field

Status
Not open for further replies.

gronsky

Technical User
Feb 8, 2002
36
US
I have a form(Financial)and tbl(Financial).

On the form is field(Date_Paid), control source; Date_Paid,
and field(Expires), control source;=DateAdd("m","12",[Date_Paid])

How would I store the info that appears in the form field(Expires) into a field in my tbl?

Thanks
 
Before we get into how to do such a thing, I gotta ask, why would you want to do that? That's a nono when it comes to data normalization. If the result is always 12 months after a field that already exists in the same table then you just perform the calculation whenever you need that value. If you just want the default value to be that then don't use the calculation as your control source but rather put it in your default value and put the new field in your control source. JHall
 
Hey JHall,

Thanks for the reply.
I tried putting the calc in the default value and it didn't work.
I'll just type in the date manually, just wanted to eliminate some typing.

~G
 
Sorry,
you can use a function to put the default value in.

=TheFunction()

then in the code module

Function TheFunction() as variant
TheFunction = DateAdd(etc...
End Function JHall
 
Hey JHall

Okay, I made the function;
Function ExpireDate() As Variant
ExpireDate = DateAdd("m", "12", Date_Paid)
End Function

Added the function to the default value, keyed in a test dues paid date; Dec 06, 1989 the value returned from ExpireDate() was Dec 30, 1900 ????

Any idears?
 
Man alive, where is my head. Hang on a sec and I'll get the right mojo. JHall
 
Okay in the AfterUpdate event of the Date_Paid control

If IsNull(Me.thedatepaidcontrolname.Value) Then
Me.theexpiredcontrolname.value=DateAdd
("m",12,Me.thedatepaidcontrolname.value)
End If



of course you can use years instead of months as long as you want to add whole years. Sorry for the bad juice. JHall
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top