By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,399 Members | 1,028 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,399 IT Pros & Developers. It's quick & easy.

How To Format Data Sent To Word?

P: n/a
I am using "acCmdOutputToRTF" to send the results of a query to Word.
This works well, but the user then has to change the page layout of
the Word document to "landscape" and use the Word "autofit to window"
menu item to make all columns visible because they "run off" the right
hand side of the page.

Is there any way to automate the Word formatting from Access?
Oct 2 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Thu, 2 Oct 2008 15:12:17 -0700 (PDT), Wayne
<cq*******@volcanomail.comwrote:

Yes. It's called Automation.
Tip: record a macro in Word to do these things like switch to
Landscape and see what kind of VBA that outputs. This will be the
basis for your code as well.
Tip: the VBA help file only gets installed with a full installation of
Office, not with a typical one.
It all starts with CreateObject("Word.Application"). I'm sure Google
has a ton of links.

-Tom.
Microsoft Access MVP

>I am using "acCmdOutputToRTF" to send the results of a query to Word.
This works well, but the user then has to change the page layout of
the Word document to "landscape" and use the Word "autofit to window"
menu item to make all columns visible because they "run off" the right
hand side of the page.

Is there any way to automate the Word formatting from Access?
Oct 3 '08 #2

P: n/a
On Oct 3, 12:54*pm, Tom van Stiphout <tom7744.no.s...@cox.netwrote:
Yes. It's called Automation.
Tip: record a macro in Word to do these things like switch to
Landscape and see what kind of VBA that outputs. This will be the
basis for your code as well.
Tip: the VBA help file only gets installed with a full installation of
Office, not with a typical one.
It all starts with CreateObject("Word.Application"). I'm sure Google
has a ton of links.

-Tom.
Microsoft Access MVP
Thanks for the heads up Tom. I know that this is rough and that there
will be a million better ways to do this, but the code below is what I
have come up with. It achieves the desired result. The only slight
annoyance is that the first row of the Word table contains the Access
query name, but I can live with that.

On Error Resume Next
DoCmd.Echo False
DoCmd.SetWarnings False
DoCmd.OpenQuery "Query_By_Form_Output"
DoCmd.RunCommand acCmdSelectAllRecords
DoCmd.RunCommand acCmdCopy
DoCmd.Close acQuery, "Query_By_Form_Output"

Dim oWord As Word.Application
Set oWord = CreateObject("Word.Application")
oWord.Visible = True
oWord.Documents.Add
oWord.Selection.PageSetup.Orientation = wdOrientLandscape
oWord.Selection.Paste
DoCmd.Echo True
DoCmd.SetWarnings True
Oct 3 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.