calculations with variables

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

Guest

I've inherited some code for putting info into a word document that looks like this:

WordObj.ActiveDocument.Bookmarks("TotProjCost").Selec
Me![TotProjCost].SetFocu
WordObj.Selection.TypeText [TotProjCost].Tex

Now I want to send the result of a calculation based on the value in [TotProjCost] to the Word document--subtracting five percent from the Total Project Cost, for example, . I've tried setting up a variable, but I must be getting the syntax wrong. Help
 
Mindy,

Take a look at how fields work in Word. You can do what you want right in Word;
jusr insert TotProjCost in from Access and have a field in the Word doc subtract
the 5%.

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
(e-mail address removed)
www.pcdatasheet.com



mindy said:
I've inherited some code for putting info into a word document that looks like this:

WordObj.ActiveDocument.Bookmarks("TotProjCost").Select
Me![TotProjCost].SetFocus
WordObj.Selection.TypeText [TotProjCost].Text

Now I want to send the result of a calculation based on the value in
[TotProjCost] to the Word document--subtracting five percent from the Total
Project Cost, for example, . I've tried setting up a variable, but I must be
getting the syntax wrong. Help!
 
mindy said:
I've inherited some code for putting info into a word document that looks like this:

WordObj.ActiveDocument.Bookmarks("TotProjCost").Select
Me![TotProjCost].SetFocus
WordObj.Selection.TypeText [TotProjCost].Text

Now I want to send the result of a calculation based on the value in [TotProjCost] to the Word document--subtracting five percent from the Total Project Cost, for example, . I've tried setting up a variable, but I must be getting the syntax wrong. Help!


The code you posted is VB code. While it will probably work
in Access VBA, it would normally be written:

WordObj.ActiveDocument.Bookmarks("TotProjCost").Select
WordObj.Selection.TypeText [TotProjCost]

To do the same kind of thing with a calculated expression,
try something like this:

WordObj.ActiveDocument.Bookmarks("somebookmark").Select
WordObj.Selection.TypeText .95 * TotProjCost
 
First you need a bookmark to accept the calculated value. So create a bookmark
named CalcValue.

Then you need to do the calculation in Access so your data needs to come from a
query. The query field might look like:
MyCalcValue:[TotProjCost]*.95

You then need a MyCalcValue field on your form.

Finally you need to pass the calculated value to the CalcValue bookmark:

WordObj.ActiveDocument.Bookmarks("CalcValue").Select
Me![MyCalcValue].SetFocus
WordObj.Selection.TypeText [MyCalcValue].Text

It's much easier to do in Word!

Steve
PC Datasheet
 
Back
Top