using vba to insert a table into word document

M

MorningStarFan

I am using MS Office 2003. I've created a form in Access and when I click a
button on the form some vba code runs that creates a word doc with data from
my access table. Problem is - I want to convert some of that text into a
table. I've found the syntax to do this but when the table range is set, all
my other text inserted into the doc before that disappears. Any ideas?

If Records = 1 Then
' If fund names are different do this...
If sFUND_NAME <> sNEXT_FUND_NAME Then
With .Selection

Set rs = dbs.OpenRecordset("SELECT XSA_NAME,
Und_Amount, XSA_P_CITY, XSA_P_STATE, CLASS, Major_Desc, FUND_NAME FROM
QRY_FORMAL_FUNDNAME WHERE FUND_NAME = '" & sFUND_NAME & "'", dbOpenDynaset)
Do While Not rs.EOF
irows = irows + 2
rs.MoveNext
Loop
irows = irows + 1
.ParagraphFormat.Alignment =
wdAlignParagraphCenter
.InlineShapes.AddPicture
FileName:="W:\Stewardship_Automation\New Picture.png", LinkToFile:=False, _
SaveWithDocument:=True
.TypeParagraph
.TypeParagraph
.Font.Size = 18
.ParagraphFormat.Alignment = 0
.Font.Bold = True
.Font.Italic = True
.TypeText Text:=sFUND_NAME
.TypeParagraph
.TypeParagraph
.TypeParagraph
.Font.Size = 14
.Font.Bold = True
.ParagraphFormat.Alignment =
wdAlignParagraphLeft
.TypeText Text:="2006-2007 RECIPIENT
INFORMATION"
.TypeParagraph



sTemp = sName & vbTab & cAmount & vbTab & sPCITY &
vbTab & sPSTATE & vbTab & sCLASS & vbTab & sMajor
'Insert a heading on the string
sTemp = "RECIPIENT" & vbTab & "AWARD" & vbTab &
"CITY" & vbTab & "STATE" & vbTab & "CLASS" & vbTab & "MAJOR" & vbCrLf & sTemp
'Insert the data into the word document
oRange.Text = sTemp
'Convert the text to a table and format the table
oRange.ConvertToTable vbTab, , , , wdAutoFitFixed, ,
, , , , , , , , , wdWord9TableBehavior
' .TypeText sTemp
'.ConvertToTable vbTab, , , ,
wdAutoFitFixed, , , , , , , , , , , wdWord9TableBehavior
.MoveDown Unit:=wdLine, Count:=irows
.InsertBreak Type:=wdPageBreak
End With

TIA,
 
M

MorningStarFan

In case anyone read this and would like to help, there is no need. I found it!

See code below... I needed to set the range for this section of the
document...so I added this and it works!

Set oRange = .Sections(1).Range
With oRange
..MoveEnd Unit:=wdCharacter, Count:=-1
..Collapse Direction:=wdCollapseEnd
..InsertParagraphAfter
..InsertAfter "End of section"
End With
 

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