View Single Post
  #1   Report Post  
Posted to microsoft.public.word.tables
MTechG
 
Posts: n/a
Default Formulas w/Imported Data

With the help of Doug Robbins I was able to populate a table in Word from
Access. When I do this I brings over just the numbers no Formatting of the
numbers. It's importing Currency and Total Calculations from a qry. Is
there a way when importing from a rs to keep the formatting as well? If not
my thoughts are to insert a formula in the cell that needs formatting and
format it that way. I've looked at a few inserting formula's in vba but
nothing working as of yet.

Any thoughts or ideas would be greatly appreciated.

D

Below is the code to import data from the database into a table and paste
the data into the table

Set Db = OpenDatabase("C:\Data Bases\MyTC.mdb")
Set qry = Db.QueryDefs("qry_NewQuoteItems2")
qry.Parameters("QuoteNum") = Me.txtPrjNum & ".0"
Set rs = myActiveRecord.OpenRecordset

Set objWord = CreateObject("Word.Application")
With objWord
.Visible = True ' Make the application visible.
.Documents.Open (stPath) ' Open the document.
Set myDoc = objWord.ActiveDocument
Set oTable = objWord.ActiveDocument.Tables(1) 'Selects the Table
End With

Set drow = oTable.Rows(1)
'Loop through all the records in the table until the end-of-file marker is
reached
Do While Not rs.EOF
'Populate the cells in the Word table with the data from the current
record
For i = 1 To rs.Fields.Count
drow.Cells(i).Range.Text = rs.Fields(i - 1)
Next i 'Add a new row to the Word table and access the next record
Set drow = oTable.Rows.Add
rs.MoveNext
Loop