Sort Columns On Export Using Word Object Model

M

mike

Hi. I have some code that takes my Access data and creates
a table in a Word doc but I'm not sure how to sort the
columns programatically. Any suggestions would be great.
Here's my code:

Dim strTableTransfersOut As String
Dim objTableTransfersOut As Word.Table

strTableTransfersOut = "From Territory" & vbTab & "From
TM" & vbTab & "Account Number" & vbTab & "Account Name" &
vbTab & "To Territory" & vbTab & "To TM" & vbTab & "Date"
& vbCr

If Not recTransfersOut.EOF Then
Do While Not recTransfersOut.EOF
strTableTransfersOut = strTableTransfersOut &
recTransfersOut("FROMTerritory") & vbTab & recTransfersOut
("FROMTM") & vbTab & recTransfersOut("AccountNumber") &
vbTab & recTransfersOut("AccountName") & vbTab &
recTransfersOut("TOTerritory") & vbTab & recTransfersOut
("TOTM") & vbTab & recTransfersOut("EffectiveDate") & vbCr

recTransfersOut.MoveNext

Loop

End If

InsertTextAtBookmark "TransfersOut", strTableTransfersOut

Set objTableTransfersOut =
m_objWord.Selection.ConvertToTable(Separator:=vbTab)

objTableTransfersOut.AutoFormat
Format:=wdTableFormatGrid8, AutoFit:=True,
ApplyShading:=True

Set objTableTransfersOut = Nothing
 
T

tina

afraid i don't have an answer for you, but i'm interested in trying your
code for myself. is part of the code missing?

strTableTransfersOut = "From Territory" & vbTab & "From
TM" & vbTab & "Account Number" & vbTab & "Account Name" &
vbTab & "To Territory" & vbTab & "To TM" & vbTab & "Date"
& vbCr

where is the system reading the values of "From Territory", "From TM", etc?
a recordset? would you mind posting the complete code so i can learn from
it? i'd really appreciate it.

and just as a thought: if you're using a recordset, could you use a query
or SQL statement as the source and sort the records there before beginning
the export?
 
K

Kevin K. Sullivan

You would do best to sort the data as you are openning the recordset. If
you are openning recTransferOut from a table, try creating a query that has
the proper ordering. You certainly don't want to sort it once you've got it
in a string or a Word table.

Show us how you open the recordset for more help.

HTH,

Kevin
 

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