Calculation on Bookmark and re-insert result at different bookmark

T

TBotsko

I've got a number of MS Word forms that are initially
filled with information from a SQL Script. I want to
perform calculations on some of the keyfields filled in
from the SQL script and then put those results into other
bookmarks in the form.

I've got code that allows me to do the proper calculations
in a table, but the form doesn't lend itself to having
tables in it.

Dim r As Row
Dim strReturnDate As String
Dim strOrder_Amount As String
For Each r In ActiveDocument.Tables(1).Rows
If Not r.IsFirst Then
' this gets you the cell content
strReturnDate = r.Cells(1).Range.Text
strOrder_Amount = r.Cells(3).Range.Text
' but you have to get rid of the end of cell
marker)
strReturnDate = Left(strReturnDate, Len
(strReturnDate) - 1)
strOrder_Amount = Left(strOrder_Amount, Len
(strOrder_Amount) - 1)
r.Cells(2).Range.Text = CStr(DateAdd("w", -30,
CDate(strReturnDate)))
cOrder_Amount = CInt(strOrder_Amount)
r.Cells(4).Range.Text = CStr(cOrder_Amount / 10)
End If
Next

Any suggestions are greatly appreciated.
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi T Botsko,

I would have the information from the SQL Script saved in the document as
Document Variables using

ActiveDocument.Variables("varname").Value =

and displayed in the document by means of a { DOCVARIABLE "varname" } field.
Then you can use the Document Variables, or the SQL data directly, in your
calculation and save the result in another Document Variable and display it
in the same way.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 

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