calculating fields

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

Guest

I need to have a field in a table or a form which calculates a date dased on a date in another field eg field "ReviewDate" already contains a date, I need a new field which calculates a new date 6 months from the "ReviewDate" date. I hope someone can help me Thanks in anticipation.
 
You can calculate 6 months from ReviewDate using the following expression:

DateAdd("m", 6, ReviewDate)

It is not recommended that you store this calculated value in a table, as
this does violate normalization rules. You can, however, use it at any time
in a Query or in a Report.

hth,
--

Cheryl Fischer, MVP Microsoft Access
Law/Sys Associates, Houston, TX


Big Phil said:
I need to have a field in a table or a form which calculates a date dased
on a date in another field eg field "ReviewDate" already contains a date, I
need a new field which calculates a new date 6 months from the "ReviewDate"
date. I hope someone can help me Thanks in anticipation.
 
Dear Cheryl, Thanks for your reply I will give it a try. Only just getting used to Access Thanks Phi

----- Cheryl Fischer wrote: ----

You can calculate 6 months from ReviewDate using the following expression

DateAdd("m", 6, ReviewDate

It is not recommended that you store this calculated value in a table, a
this does violate normalization rules. You can, however, use it at any tim
in a Query or in a Report

hth
-

Cheryl Fischer, MVP Microsoft Acces
Law/Sys Associates, Houston, T


Big Phil said:
I need to have a field in a table or a form which calculates a date dase
on a date in another field eg field "ReviewDate" already contains a date,
need a new field which calculates a new date 6 months from the "ReviewDate
date. I hope someone can help me Thanks in anticipation
 
Dear Cheryl, Please bear with me, I have tried to enter the formula in a form but all i get in the form field is a error,where actualy should I enter the formula. Thanks Phil
 
Dear Cheryl, Playing about I managed to get this to calculate the new date but all records now show the same date.?

DateAdd("m",6,[reviewdate]) i put the formula in the form property default value is this correct
 
Hi Phil,

No problem ...

In the scenario I think you are using: You enter a ReviewDate on your form
and want the other control (FollowUpDate, maybe?) to calculate a date 6
months forward. You will need to use a bit of VBA code in two events.
(Don't panic - this is pretty easy.) Here are the steps:

The first event that you will add code to is the AfterUpdate event of the
ReviewDate control. The reason you add code here is so that if the
ReviewDate control is updated, the FollowUpDate control will be
recalculated. Here are the steps:

1. Right click on the ReviewDate control and select Properties.

2. When the Properties sheet opens, click the tab labeled Event.

3. In the grid below, locate the row labeled, After Update. It should be
blank. Click anywhere in the white space to the right of the label and you
will see a downward-pointing arrow appear, indicating that this is also a
ComboBox. Click the arrow and select "Event Procedure".

4. Then, notice that there is an ellipsis or three little dots (...) to the
right of the ComboBox. Click the ellipsis and you will open a code window.
You will see that Access has given you a space for entering some code in
this event - it will look something like the following:

Private Sub ReviewDate_AfterUpdate(Cancel As Integer)

End Sub

5. After the "Private Sub ReviewDate_AfterUpdate(Cancel As Integer)" line,
insert the following:

Me!FollowUpDate = DateAdd("m", 6, Me!ReviewDate)

6. Click the Save icon and close the Microsoft Visual Basic code window.

The second event you will add code to is the Form's On Current event.
This event will cause the FollowUpDate to be calculated if you scroll
through various records *without making a change* to ReviewDate.

1. Still looking at the Properties sheet, notice that there is a combo box
at the top of the window. This combo box contains a list of all of the
objects for which you can see properties.

2. Click the downward-pointing arrow at the right edge of this combo box
and find the item in the list which says "Form".

3. You will now have opened the Properties sheet for your form.

4. Click the "Event" tab and look for the On Current event. It should be
the first event listed. Click anywhere in the white space to the right of
the label and you will see a downward-pointing arrow appear. Click the
arrow and select "Event Procedure". Then, click the ellipsis ( ... ) at
the right edge of the On Current property.

5. A code window will open that looks like the following:

Private Sub Form_Current()

End Sub

6. After the line which says "Private Sub Form_Current()", insert the
following:

Me!FollowUpDate = DateAdd("m", 6, Me!ReviewDate)

7. Click the Save button.


Let us know how this works ...

--

Cheryl Fischer, MVP Microsoft Access
Law/Sys Associates, Houston, TX


Big Phil said:
Dear Cheryl, Please bear with me, I have tried to enter the formula in a
form but all i get in the form field is a error,where actualy should I enter
the formula. Thanks Phil
 
Phil,

As Cheryl suggested, I would also recommend that the calculated value
*not* be stored in the table. That means the textbox on your form for
the calculated date will be an *unbound* textbox. Use the expression,
preceded by a = sign, in the Control Source property of the textbox,
like this...
=DateAdd("m",6,[ReviewDate])
 
No, Phil, the Default Value property is not the best place. As
mentioned in my other post, put it in the Control Source property of an
unbound textbox.

The other way to do it would be to have your form based on a query, and
the query based on your table. Once again, do not have the FollowupDate
(or whatever you want to call it) in the table. But you can make a
calculated field in the query by putting this is ther Field row of a
blank column in the query design grid...
FollowupDate: DateAdd("m",6,[reviewdate])
and then you can have a textbox on the form which is bound to this query
field.
 
Thanks to you both I used Cheryls Advice and it seems to work, I owe you both Thank you. I was almost ready to give up. Perfaps you could recommend some good reading that could help me. Thanks Again!!! Big Phil (Blackpool England)
 
You're welcome, Phil.

As to good reading, you might want to browse Access MVP John Viescas'
website for his recommendations:
http://www.viescas.com/Info/books.htm#Database Design.


--

Cheryl Fischer, MVP Microsoft Access
Law/Sys Associates, Houston, TX


Big Phil said:
Thanks to you both I used Cheryls Advice and it seems to work, I owe you
both Thank you. I was almost ready to give up. Perfaps you could recommend
some good reading that could help me. Thanks Again!!! Big Phil (Blackpool
England)
 
Back
Top