S
Staunts
Hi there,
I have the following code that I want to print out a series of word
docs and output them with bookmarks inserted. The code runs fine ,
until I put the loop statement in and ask it to open a recordset to
pull out the file names of the documents.
Can any of you have a look and see what I might be doing wrong ?
Using Access 2K/Word 2K
I have the following libraries referenced:
Visual Basic for Applications
Microsoft access 9.0 Object Library
Microsoft DAO 3.6 Object Library
Microsoft Word 9.0 Object Library
Ole Automation
It seems to get a mismatch error on this line:
"Set WordDoc = WordObj.Documents.Open(rst!DocFileName)"
-----CODE STARTS HERE------
Dim rst As DAO.Recordset
Dim WordObj As Word.Application
Dim WordDoc As Word.Document
Dim WordRange As Word.Range
Dim ProjectName As String
Dim ProjectDate As String
ProjectName = Forms!frmProject!Proj_Title
ProjectDate = Forms!frmProject!Proj_StartDate
Set rst = CurrentDb.OpenRecordset("SELECT DocFilename FROM
tblProjPrintDocs")
Do Until rst.EOF
Set WordObj = CreateObject("Word.Application")
Set WordDoc = WordObj.Documents.Open(rst!DocFileName)
Set WordRange = WordDoc.Goto(What:=wdGoToBookmark,
Name:="ProjectName")
WordRange.InsertAfter ProjectName
'
Set WordRange = WordDoc.Goto(What:=wdGoToBookmark,
Name:="ProjectDate")
WordRange.InsertAfter ProjectDate
WordDoc.PrintOut Background:=False
Set WordObj = Nothing
rst.MoveNext
Loop
WordApp.Quit
rst.Close
------CODE ENDS HERE--------------------
Any help would be greatly appreciated.
I have the following code that I want to print out a series of word
docs and output them with bookmarks inserted. The code runs fine ,
until I put the loop statement in and ask it to open a recordset to
pull out the file names of the documents.
Can any of you have a look and see what I might be doing wrong ?
Using Access 2K/Word 2K
I have the following libraries referenced:
Visual Basic for Applications
Microsoft access 9.0 Object Library
Microsoft DAO 3.6 Object Library
Microsoft Word 9.0 Object Library
Ole Automation
It seems to get a mismatch error on this line:
"Set WordDoc = WordObj.Documents.Open(rst!DocFileName)"
-----CODE STARTS HERE------
Dim rst As DAO.Recordset
Dim WordObj As Word.Application
Dim WordDoc As Word.Document
Dim WordRange As Word.Range
Dim ProjectName As String
Dim ProjectDate As String
ProjectName = Forms!frmProject!Proj_Title
ProjectDate = Forms!frmProject!Proj_StartDate
Set rst = CurrentDb.OpenRecordset("SELECT DocFilename FROM
tblProjPrintDocs")
Do Until rst.EOF
Set WordObj = CreateObject("Word.Application")
Set WordDoc = WordObj.Documents.Open(rst!DocFileName)
Set WordRange = WordDoc.Goto(What:=wdGoToBookmark,
Name:="ProjectName")
WordRange.InsertAfter ProjectName
'
Set WordRange = WordDoc.Goto(What:=wdGoToBookmark,
Name:="ProjectDate")
WordRange.InsertAfter ProjectDate
WordDoc.PrintOut Background:=False
Set WordObj = Nothing
rst.MoveNext
Loop
WordApp.Quit
rst.Close
------CODE ENDS HERE--------------------
Any help would be greatly appreciated.