Log in

View Full Version : [SOLVED:] Looking to find out how to create a Word document from Access, NOT mail merge



drcoz
08-24-2017, 10:29 AM
I have a weekly report that requires several hours to put together. I've decided to put the data into Access and then use VBA code to put it into a new word document.

I've searched on how to do this and I keep coming up with nothing or tables. I don't want tables as the paragraphs will be numbers:

1 2 3, then sub to a b c then sub to i ii iii format.

The data is coming from 7 different sections within my organization.

I'd post my code, but the forum keeps telling me it has URL or bad words in it. So I'll attach it, if that works

I've done something like this for PowerPoint, but when trying the same code here it does not work. again I don't want to add tables as the report has to be in a specific format. I also don't want to do mail merge as each area may have from 3 to 30 different topics for this report when generated.

Well thanks for you time.

macropod
08-24-2017, 05:06 PM
Your description suggests you're trying to generate some kind of report from Access, in which case you should ask your question in the Access forum: http://www.vbaexpress.com/forum/forumdisplay.php?16-Access-Help

drcoz
08-25-2017, 03:50 AM
I'm trying to export data from Access to a new Word document, without using mail merge and not putting the data into a table. Do I still need to post in Access Forum?

macropod
08-25-2017, 05:36 AM
So use some code to convert the Access report table(s) to text.

drcoz
08-29-2017, 08:14 AM
Found this code by Daniel Pineault that solved what I needed.


Set rs1 = db.OpenRecordset("qryDirPriorities", dbOpenDynaset)

With rs1
If .RecordCount <> 0 Then
.MoveLast 'Ensure proper count by moving to last record
iRecCount = .RecordCount 'Number of records returned by the table/query ROW
.MoveFirst 'Move to first record
iFldCount = .Fields.Count 'Number of fields/columns returned by the table/query COLUMS

objWord.ActiveWindow.View.Type = wdPrintView 'Switch to print preview mode (not required just a personal preference)
Else
MsgBox "There are no records returned by the specified queries/SQL statement.", vbCritical + vbOKOnly, "No data to generate an Word spreadsheet with"
GoTo SubError
End If
End With

C = 1

While Not rs1.EOF
For C = 1 To iRecCount
.TypeText Chr(9) & Chr(9) & FormatRoman(C) & "." & " (U//FOUO) Priority " & Nz(rs1.Fields(0)) & ". " & Nz(rs1.Fields(1))
.TypeParagraph
rs1.MoveNext
Next
Wend

rs1.Close
iRecCount = 0
iFldCount = 0