Help with looping thru a query and printing word docs

S

Staunts

Hi all,

I am hoping someone can help. I need to run some sql and have it use
the results of that query to print out some documents.

Here is the query:

SELECT tblMyTable.Id, tblMyTable.Desc, tblMyTable.DocName
FROM tblMyTable
WHERE (((tblMyTable.Id)>5));

Results in this:

1 Desc1 Doc1.doc
2 Desc2 Doc2.doc
3 Desc3 Doc3.doc
4 Desc4 Doc4.doc


Ok ,

I need to loop thru the resultant set and print the Word Document
(DocName).

Here's the code I have for the printing part of that:

Dim WordApp As Object
Set WordApp = CreateObject("Word.Application")
WordApp.Documents.Open ("MyDoc.doc")
WordApp.ActiveDocument.PrintOut False
WordApp.ActiveDocument.Close False
WordApp.Quit
Set WordApp = Nothing

Does anyone know how I can do this, i.e. print docs Doc1/Doc2/Doc3/Doc4
?

ay help would be appreciated.

cheers
 
S

Steve Schapel

Staunts,

I think it should work like this...

Dim rst As DAO.Recordset
Dim WordApp As Object
Set rst = CurrentDb.OpenRecordset("SELECT DocName FROM YourQuery")
Set WordApp = CreateObject("Word.Application")
Do Until rst.EOF
WordApp.Documents.Open (rst!DocName)
WordApp.ActiveDocument.PrintOut False
WordApp.ActiveDocument.Close False
rst.MoveNext
Loop
WordApp.Quit
rst.Close
Set WordApp = Nothing
Set rst = Nothing
 
Top