clare_voiant
Board Regular
- Joined
- Mar 20, 2002
- Messages
- 76
Hi,
having spent 2 days (with help) writing code to mailmerge a word document with a query from Access, Ive discovered that it only works successfully if the VB window is open but minimised.
the code is below, but would be grateful for a bit of code to insert at the beginning and the end that opens and minimises the VB window then closes it after. (this is probably not the best way of doing it, but am running out of time and my VB skills are limited)
thanks in advance
Clare
Option Compare Database
Option Explicit
Dim objword As Word.Application
Public Sub GenerateChequeLetter()
Dim strSQL As String
Dim docChequeLetter As Word.Document
Set objword = New Word.Application
MsgBox ("Warning..... Ensure All Word or Other Access Applications are closed before continuing.... This action takes a while please be patient.... its worth it..... honest")
objword.Visible = True
With objword
Set docChequeLetter = .Documents.Add(Template:="g:\P2EDocs\Cheque Letter")
With docChequeLetter.MailMerge
.OpenDataSource Name:="G:\ITT 2002-2003\Passport to Export\Passport to Export.mdb", _
LinkToSource:=True, AddToRecentFiles:=False, _
Connection:="QUERY QryChequeLetter", SQLStatement:= _
"SELECT * FROM 'QryChequeLetter'"
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=True
End With
.Documents(1).SaveAs ("G:\P2EDocs\Docs\ChequeLetters") & CStr(Format(Now(), " DD MMMM YYYY") & ".doc")
.Application.Documents(docChequeLetter).Close wdDoNotSaveChanges
End With
Set objword = Nothing
Set docChequeLetter = Nothing
End Sub
having spent 2 days (with help) writing code to mailmerge a word document with a query from Access, Ive discovered that it only works successfully if the VB window is open but minimised.
the code is below, but would be grateful for a bit of code to insert at the beginning and the end that opens and minimises the VB window then closes it after. (this is probably not the best way of doing it, but am running out of time and my VB skills are limited)
thanks in advance
Clare
Option Compare Database
Option Explicit
Dim objword As Word.Application
Public Sub GenerateChequeLetter()
Dim strSQL As String
Dim docChequeLetter As Word.Document
Set objword = New Word.Application
MsgBox ("Warning..... Ensure All Word or Other Access Applications are closed before continuing.... This action takes a while please be patient.... its worth it..... honest")
objword.Visible = True
With objword
Set docChequeLetter = .Documents.Add(Template:="g:\P2EDocs\Cheque Letter")
With docChequeLetter.MailMerge
.OpenDataSource Name:="G:\ITT 2002-2003\Passport to Export\Passport to Export.mdb", _
LinkToSource:=True, AddToRecentFiles:=False, _
Connection:="QUERY QryChequeLetter", SQLStatement:= _
"SELECT * FROM 'QryChequeLetter'"
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=True
End With
.Documents(1).SaveAs ("G:\P2EDocs\Docs\ChequeLetters") & CStr(Format(Now(), " DD MMMM YYYY") & ".doc")
.Application.Documents(docChequeLetter).Close wdDoNotSaveChanges
End With
Set objword = Nothing
Set docChequeLetter = Nothing
End Sub