
Export Access Queries to a Word Doc via a VB6 Program
As the title suggests I'm doing a little of everything here. Anyway, here's
my situation. My program is written in VB 6 using MS Access as the
database. Not all of my users will have Access however. I have many
queries written in Access and want to export those queries to a word doc via
automation. In my code snippet below I know I could replace "qry1" on the
.Content.InsertAfter...line with a string variable or literal text.
However, I want to export the query (and actually many others) to the word
doc to automate the creation of report.
In Access I could do this using OutputTo, but again my users won't
necessarily have Access.
Any thoughts on revising the code below to perform such a function?
Thanks in advance,
Allan
--------------------------------------
Public Function CreateReport()
Dim wrdApp As New Word.Application
Dim wrdDoc As Word.Document
Dim x As Integer
Dim y As Integer
Dim dbsMSWL As Database
Dim qry1 As Recordset
Set dbsMSWL = OpenDatabase(App.Path & "\mswl.mdb")
Set qry1 = dbsMSWL.OpenRecordset("qryTeamStandings")
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Add
With wrdDoc
.Content.InsertAfter qry1
.SaveAs ("C:\MyNewWordDoc.doc")
.Close
End With
wrdApp.Quit
Set wrdDoc = Nothing
Set wrdApp = Nothing
dbsMSWL.Close
End Function