displaying generated date in a form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Currently I have a form with the following feilds; [purchase date] [warranty length] & [warranty expiration]

what i want to do is calculate the warranty expiration date using the purchase date and the warranty length.

SO

I set the default value of the warranty expiration field to:

=DateAdd("yyyy",[Warranty length],[Purchae Date])

and added a macro to warranty length, so that on change it will requery warranty expiration.

Currently, I get no result the field remains blank.

Suggestions???
 
Joseph,

Putting the formula in the control's DefaultValue property only helps when
you first move to that record. If you want to refresh the field based on
changes made to other controls, you need to affect its Value property. So,
in the AfterUpdate event for both [Warranty length] AND [Purchase Date], add
the following:
RecalculateExpiry

Then add the following procedure to the form:
Private Sub RecalculateExpiry()
Me("waranty expiration") = DateAdd("yyyy", Nz(Me("Warranty length"),
1), Nz(Me("Purchase Date"), Date()))
End Sub

To avoid getting a blank field when you first move to the record, try using
this in the control's DefaultValue property:
=DateAdd("yyyy", Nz([Warranty length], 1), Nz([Purchase Date], Date()))

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Microsoft Access 2003 VBA Programmer's Reference
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0764559036.html


Joseph Atie said:
Currently I have a form with the following feilds; [purchase date]
[warranty length] & [warranty expiration]
what i want to do is calculate the warranty expiration date using the
purchase date and the warranty length.
SO

I set the default value of the warranty expiration field to:

=DateAdd("yyyy",[Warranty length],[Purchae Date])

and added a macro to warranty length, so that on change it will requery warranty expiration.

Currently, I get no result the field remains blank.

Suggestions???
 
Ive never used this method before. I must be doing something wrong.

When i try to execute the function (by changing one of the values in the open form) I get an error message about not being able to find the macro RecalculateExpiry.

what am i missing?

I simple opened the code section for the form and copy/pasted the function as you have it written, then change the field names. Oh and i added the added the afterupdate function call as "RecalculateExpiry"

Graham R Seach said:
Joseph,

Putting the formula in the control's DefaultValue property only helps when
you first move to that record. If you want to refresh the field based on
changes made to other controls, you need to affect its Value property. So,
in the AfterUpdate event for both [Warranty length] AND [Purchase Date], add
the following:
RecalculateExpiry

Then add the following procedure to the form:
Private Sub RecalculateExpiry()
Me("waranty expiration") = DateAdd("yyyy", Nz(Me("Warranty length"),
1), Nz(Me("Purchase Date"), Date()))
End Sub

To avoid getting a blank field when you first move to the record, try using
this in the control's DefaultValue property:
=DateAdd("yyyy", Nz([Warranty length], 1), Nz([Purchase Date], Date()))

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Microsoft Access 2003 VBA Programmer's Reference
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0764559036.html


Joseph Atie said:
Currently I have a form with the following feilds; [purchase date]
[warranty length] & [warranty expiration]
what i want to do is calculate the warranty expiration date using the
purchase date and the warranty length.
SO

I set the default value of the warranty expiration field to:

=DateAdd("yyyy",[Warranty length],[Purchae Date])

and added a macro to warranty length, so that on change it will requery warranty expiration.

Currently, I get no result the field remains blank.

Suggestions???
 
Sleek,

<<what am i missing?>>
Don't know. Post what you have now.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Microsoft Access 2003 VBA Programmer's Reference
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0764559036.html


sleek said:
Ive never used this method before. I must be doing something wrong.

When i try to execute the function (by changing one of the values in the
open form) I get an error message about not being able to find the macro
RecalculateExpiry.
what am i missing?

I simple opened the code section for the form and copy/pasted the function
as you have it written, then change the field names. Oh and i added the
added the afterupdate function call as "RecalculateExpiry"
Graham R Seach said:
Joseph,

Putting the formula in the control's DefaultValue property only helps when
you first move to that record. If you want to refresh the field based on
changes made to other controls, you need to affect its Value property. So,
in the AfterUpdate event for both [Warranty length] AND [Purchase Date], add
the following:
RecalculateExpiry

Then add the following procedure to the form:
Private Sub RecalculateExpiry()
Me("waranty expiration") = DateAdd("yyyy", Nz(Me("Warranty length"),
1), Nz(Me("Purchase Date"), Date()))
End Sub

To avoid getting a blank field when you first move to the record, try using
this in the control's DefaultValue property:
=DateAdd("yyyy", Nz([Warranty length], 1), Nz([Purchase Date], Date()))

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Microsoft Access 2003 VBA Programmer's Reference
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0764559036.html


Joseph Atie said:
Currently I have a form with the following feilds; [purchase date]
[warranty length] & [warranty expiration]
what i want to do is calculate the warranty expiration date using the
purchase date and the warranty length.
SO

I set the default value of the warranty expiration field to:

=DateAdd("yyyy",[Warranty length],[Purchae Date])

and added a macro to warranty length, so that on change it will
requery
warranty expiration.
Currently, I get no result the field remains blank.

Suggestions???
 
Back
Top