Ms Access ReportOutput to MsWord but FormattingOut

imfarhan

Board Regular
Joined
Jan 29, 2010
Messages
125
Office Version
  1. 2016
Platform
  1. Windows
Hi All,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
I have got a report generate the output in excel is fine, but the user would like to see the output in Ms Word.
I have used the following code to generate the results in Ms Word , the results are fine but the formatting is out.
<o:p></o:p>
appAccess.DoCmd.OutputTo acOutputReport, ReportName, OPType, DestinationPath & DestinationName<o:p></o:p>

To get the right format(Borders on Table ) I can generate the output on SNP format. But I would like the output only in DOC format so the user can further edit as per their requirement

I would be grateful if you could give any suggestion please.

Many thanks
Regards
Farhan

Trying to use the following VBA code but giving me error UserDefined Type not defined
The following code i'm trying to use on MsAccess-2003
Sub Export_Word()<o:p></o:p>
<o:p></o:p>
Dim rsdata As New ADODB.Recordset<o:p></o:p>
Dim strSql As String<o:p></o:p>
<o:p></o:p>
strSql = "SELECT * FROM Table1;"<o:p></o:p>
rsdata.Open strSql, CurrentProject.Connection<o:p></o:p>
<o:p></o:p>
Dim oWord As Word.Application<o:p></o:p>
Dim oDoc As Word.Document<o:p></o:p>
Set oWord = New Word.Application<o:p></o:p>
Set oDoc = New Word.Document<o:p></o:p>
<o:p></o:p>
oDoc.ActiveWindow.Selection.Tables.Add Range:=oDoc.ActiveWindow.Selection.Range, numrows:=1, numcolumns:=3<o:p></o:p>
'numcolumns:= has to be customized<o:p></o:p>
<o:p></o:p>
'Create headers<o:p></o:p>
oDoc.Tables(1).Columns(1).Cells(1).Range.Text = "..test1.."<o:p></o:p>
oDoc.Tables(1).Columns(2).Cells(1).Range.Text = "..test2.."<o:p></o:p>
oDoc.Tables(1).Columns(3).Cells(1).Range.Text = "..test3.."<o:p></o:p>
'etc.<o:p></o:p>
<o:p></o:p>
'Export Data<o:p></o:p>
i = 1<o:p></o:p>
Do Until rsdata.EOF<o:p></o:p>
oDoc.Tables(1).Columns(1).Cells.Add<o:p></o:p>
oDoc.Tables(1).Columns(1).Cells(i + 1).Range.Text = rsdata.Fields(0)<o:p></o:p>
oDoc.Tables(1).Columns(2).Cells(i + 1).Range.Text = rsdata.Fields(1)<o:p></o:p>
oDoc.Tables(1).Columns(3).Cells(i + 1).Range.Text = rsdata.Fields(2)<o:p></o:p>
'etc.<o:p></o:p>
i = i + 1<o:p></o:p>
<o:p></o:p>
rsdata.MoveNext<o:p></o:p>
<o:p></o:p>
Loop<o:p></o:p>
<o:p></o:p>
oDoc.ActiveWindow.Document.SaveAs ("C:\Export.doc")<o:p></o:p>
<o:p></o:p>
oDoc.ActiveWindow.Document.Close True<o:p></o:p>
oWord.Quit True<o:p></o:p>
Set oDoc = Nothing<o:p></o:p>
Set oWord = Nothing<o:p></o:p>
<o:p></o:p>
rsdata.Close<o:p></o:p>
Set rsdata = Nothing<o:p></o:p>
 
Last edited:

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Did you set a reference to Word?

Also, as you have seen, outputting an Access report to Word without using some automation doesn't give the correct layout. That is because the output is rtf, and lines / logos etc don't get reproduced.

Denis
 
Last edited:
Upvote 0
Thanks a lot Denis,
I just add the reference obje "MS Word 9.0 object library" and its works..
But the formatting need to be done meaning Borders created which is good but would like to change the layout of the word document It should be landscape because I have got around 13 coulums in the source table.

I hope, you people have no problem if I can post more related to same problem if I get stuck through any formatting issue i.e. layout change, header and so on.

Many thanks
Farhan
 
Last edited:
Upvote 0
You get a lot more control by building the Word file as you want it, then merging the Access data to that document.
If you go to http://www.helenfeddema.com and download article #141 from the Access Archon page you will get a detailed example of how to do it.

Denis
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,297
Members
452,903
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top