L
Leigh46137
Hope someone can help me out here!
Versions:
I am using Access and Word 2000.
What I need to accomplish:
I need to Merge a series of 10-15 word documents with the data in the record
that is currently displayed. I also have a couple of other forms with one doc
that merge and print separately, not as part of the series.
How it is set up now:
Currently, I have a query set up for each merge that I need to perform. In
the RecordID field of the query, I have set criteria like this:
[Forms]![formname]![RecordID]. The Word docs point to the query in the
database and are set to preview the data -- there will only be one record, so
this works fine. The user clicks one button to merge and print. The code
walks through the list of docs and calls the print procedure for each file.
Private Sub Print(stFile As String)
Dim apWord As Word.Document
Set apWord = GetObject(stFile & ".doc", "Word.Document")
apWord.Application.Visible = True
apWord.Application.Options.PrintBackground = False
apWord.Application.ActiveDocument.PrintOut
apWord.Application.Quit SaveChanges:=False
Set apWord = Nothing
End Sub
There are a few problems with this:
1. It opens Word, then opens the document every single time. It should only
open Word once, then open each document, print and close the document.
2. It opens a new instance of Access every single time, too! It is the new
instance that is used to get the data, and since there is no form displayed,
the query can't find the RecordID, so it prompts for the parameter.
3. The query sometimes can't find the record until I have closed and
re-opened the form -- even when I click the save button to save the record
first.
4. The most aggravating problem is that yesterday this worked! It used the
instance of Access already open and therefore knew which record to use. I
have no clue what I changed to make it not work anymore. I only added a new
table, query, form and merge doc. (This one prints separate from the series.)
Any suggestion on how I can make this work?
Thanks!
Versions:
I am using Access and Word 2000.
What I need to accomplish:
I need to Merge a series of 10-15 word documents with the data in the record
that is currently displayed. I also have a couple of other forms with one doc
that merge and print separately, not as part of the series.
How it is set up now:
Currently, I have a query set up for each merge that I need to perform. In
the RecordID field of the query, I have set criteria like this:
[Forms]![formname]![RecordID]. The Word docs point to the query in the
database and are set to preview the data -- there will only be one record, so
this works fine. The user clicks one button to merge and print. The code
walks through the list of docs and calls the print procedure for each file.
Private Sub Print(stFile As String)
Dim apWord As Word.Document
Set apWord = GetObject(stFile & ".doc", "Word.Document")
apWord.Application.Visible = True
apWord.Application.Options.PrintBackground = False
apWord.Application.ActiveDocument.PrintOut
apWord.Application.Quit SaveChanges:=False
Set apWord = Nothing
End Sub
There are a few problems with this:
1. It opens Word, then opens the document every single time. It should only
open Word once, then open each document, print and close the document.
2. It opens a new instance of Access every single time, too! It is the new
instance that is used to get the data, and since there is no form displayed,
the query can't find the RecordID, so it prompts for the parameter.
3. The query sometimes can't find the record until I have closed and
re-opened the form -- even when I click the save button to save the record
first.
4. The most aggravating problem is that yesterday this worked! It used the
instance of Access already open and therefore knew which record to use. I
have no clue what I changed to make it not work anymore. I only added a new
table, query, form and merge doc. (This one prints separate from the series.)
Any suggestion on how I can make this work?
Thanks!