M
Mike
Hi, I would like to perform a mailmerge by clicking a button on an
access form.
I have the following code:
Dim objWord As Word.Application
Dim objDoc As Word.Document
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Open("E:\Rechtsbijstand Certificaten\RB
Certificaat Certificaat.doc")
With objWord
.Visible = True
.WindowState = wdWindowStateMaximize
End With
objDoc.MailMerge.OpenDataSource _
Name:=CurrentDb.Name, _
LinkToSource:=True, _
Connection:="TABLE TblSamenvoeg", _
SQLStatement:="Select * from [TblSamenvoeg] WHERE [PolisId]="&
Form_FormPolInv.PolisId.Value
objDoc.MailMerge.Execute
'because I get 2 documents, the original and the merged one I use:
If InStr(ActiveDocument.Name, "RB Certificaat Certificaat") = 0 Then
Set DocResult = Documents(1)
Else
Set DocResult = ActiveDocument
End If
objWord.ActiveDocument.PrintOut
But at the InStr-line I get an error (4248) saying that the document is
not there, but they are there!
So the merging goes OK, but the printing isn't done.
What is going wrong?
Thanks, Mike
access form.
I have the following code:
Dim objWord As Word.Application
Dim objDoc As Word.Document
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Open("E:\Rechtsbijstand Certificaten\RB
Certificaat Certificaat.doc")
With objWord
.Visible = True
.WindowState = wdWindowStateMaximize
End With
objDoc.MailMerge.OpenDataSource _
Name:=CurrentDb.Name, _
LinkToSource:=True, _
Connection:="TABLE TblSamenvoeg", _
SQLStatement:="Select * from [TblSamenvoeg] WHERE [PolisId]="&
Form_FormPolInv.PolisId.Value
objDoc.MailMerge.Execute
'because I get 2 documents, the original and the merged one I use:
If InStr(ActiveDocument.Name, "RB Certificaat Certificaat") = 0 Then
Set DocResult = Documents(1)
Else
Set DocResult = ActiveDocument
End If
objWord.ActiveDocument.PrintOut
But at the InStr-line I get an error (4248) saying that the document is
not there, but they are there!
So the merging goes OK, but the printing isn't done.
What is going wrong?
Thanks, Mike