creating word mailing labels with Mail Merge 
Author Message
 creating word mailing labels with Mail Merge

Im trying to create Word  mailing labels with Mail Merge.
I ve just copied the code generated by recording a Word macro; but when i
execute the macro it produces an error at line
"ActiveDocument.MailMerge.Execute pause:=True"
I cant understand why it fails here. Could anybody help me?
thanks a lot.


Thu, 19 Aug 2004 08:18:02 GMT  
 creating word mailing labels with Mail Merge
Hi, julin,

What is the exact wording of the error message when it fails? Does it help to
remove the "pause:=True" part?

--
Regards,
Jay Freedman
Microsoft Word MVP        Word MVP FAQ site: http://www.mvps.org/word


Quote:
> Im trying to create Word  mailing labels with Mail Merge.
> I ve just copied the code generated by recording a Word macro; but when i
> execute the macro it produces an error at line
> "ActiveDocument.MailMerge.Execute pause:=True"
> I cant understand why it fails here. Could anybody help me?
> thanks a lot.



Thu, 19 Aug 2004 09:49:45 GMT  
 creating word mailing labels with Mail Merge
[Posting email response. Please keep all replies in the newsgroup so that others
can follow.]

Hi, Julin,

That error isn't one I'm familiar with (when I check it in Word VBA, it says
it's an "Application-defined or object-defined error"). But what I suspect is
that the merge fields in the main merge document don't match the field names in
Access. This may be because of a spelling error in the merge fields, or because
the merge document is not properly opened, or because there's something wrong
with the Access database.

--
Regards,
Jay Freedman
Microsoft Word MVP        Word MVP FAQ site: http://www.mvps.org/word

"julin atienza" replied:

Quote:
>The error is :
>-Error "4605" in executing time:
>this method or property is not available because The principal active
>document of combination of correspondence does not have combination
>fields- If i remove pause:=True the program fails with the same error;
>and if i remove all the sentence
>-ActiveDocument.MailMerge.Execute pause:=True -
>it creates a Word document with mailing labels fields empty-it doesnt
>read any data from Access-.



Quote:
> Hi, julin,

> What is the exact wording of the error message when it fails? Does it help to
> remove the "pause:=True" part?

> --
> Regards,
> Jay Freedman
> Microsoft Word MVP        Word MVP FAQ site: http://www.mvps.org/word



> > Im trying to create Word  mailing labels with Mail Merge.
> > I ve just copied the code generated by recording a Word macro; but when i
> > execute the macro it produces an error at line
> > "ActiveDocument.MailMerge.Execute pause:=True"
> > I cant understand why it fails here. Could anybody help me?
> > thanks a lot.



Fri, 20 Aug 2004 05:58:06 GMT  
 creating word mailing labels with Mail Merge
I cant find the problem, the merge fields in the main merge document  match
the field names in Access. I have created a new Data Base with new tables
and it doesnt run. So i send you the code. It is maybe a problem with the
ActiveDocument at the moment running .Execute but i cant resolve it.

Private Sub cmdWord_Click()
Dim w As New Word.Application
w.Documents.Add

w.ChangeFileOpenDirectory (App.Path)
w.ActiveDocument.SaveAs FileName:="VBASample_" & _
 ".doc", _
FileFormat:=wdFormatDocument, _
LockComments:=False, Password:="", _
ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False

  w.ActiveDocument.MailMerge.MainDocumentType = wdMailingLabels

  w.ActiveDocument.MailMerge.OpenDataSource Name:= _
        App.Path & "\julian.mdb", _
        ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
        AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="",
_
        WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False,
_
        Format:=wdOpenFormatAuto, Connection:="TABLE julian", SQLStatement:=
_
        "SELECT Nombre, Dni FROM [julian]", SQLStatement1:=""

  w.Application.MailingLabel.DefaultPrintBarCode = False
  'w.Application.MailingLabel.CreateNewDocument

  w.Application.MailingLabel.CreateNewDocument Name:="2160 mini", Address:=
_
        "Nombre: ?Nombre?" & Chr(13) & "dni: ?Dni?" & Chr(13), AutoText:="",
_
        LaserTray:=wdPrinterManualFeed

    If ActiveDocument.MailMerge.State = wdMainAndDataSource Then
    With w.ActiveDocument.MailMerge

        .Destination = wdSendToNewDocument
        .MailAsAttachment = False
        .MailAddressFieldName = ""
        .MailSubject = ""
        .SuppressBlankLines = True
        With .DataSource
           .FirstRecord = wdDefaultFirstRecord
           .LastRecord = wdDefaultLastRecord
        End With
        .Execute pause:=True 'this method is not implemented in the active
document

    End With
    End If
    w.ActiveDocument.SaveAs FileName:="etiquetas.doc", FileFormat:= _
        wdFormatDocument, LockComments:=False, Password:="",
AddToRecentFiles:= _
        True, WritePassword:="", ReadOnlyRecommended:=False,
EmbedTrueTypeFonts:= _
        False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
        SaveAsAOCELetter:=False

'crea las etiquetas************************************************

'cierra el documento sin guardar los cambios

w.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges

'termina la aplicacin Word
w.Application.Quit

Set w = Nothing
End Sub


Quote:
> [Posting email response. Please keep all replies in the newsgroup so that
others
> can follow.]

> Hi, Julin,

> That error isn't one I'm familiar with (when I check it in Word VBA, it
says
> it's an "Application-defined or object-defined error"). But what I suspect
is
> that the merge fields in the main merge document don't match the field
names in
> Access. This may be because of a spelling error in the merge fields, or
because
> the merge document is not properly opened, or because there's something
wrong
> with the Access database.

> --
> Regards,
> Jay Freedman
> Microsoft Word MVP        Word MVP FAQ site: http://www.mvps.org/word

> "julin atienza" replied:

> >The error is :

> >-Error "4605" in executing time:

> >this method or property is not available because The principal active

> >document of combination of correspondence does not have combination

> >fields- If i remove pause:=True the program fails with the same error;

> >and if i remove all the sentence

> >-ActiveDocument.MailMerge.Execute pause:=True -

> >it creates a Word document with mailing labels fields empty-it doesnt

> >read any data from Access-.



> > Hi, julin,

> > What is the exact wording of the error message when it fails? Does it
help to
> > remove the "pause:=True" part?

> > --
> > Regards,
> > Jay Freedman
> > Microsoft Word MVP        Word MVP FAQ site: http://www.mvps.org/word



> > > Im trying to create Word  mailing labels with Mail Merge.
> > > I ve just copied the code generated by recording a Word macro; but
when i
> > > execute the macro it produces an error at line
> > > "ActiveDocument.MailMerge.Execute pause:=True"
> > > I cant understand why it fails here. Could anybody help me?
> > > thanks a lot.



Fri, 20 Aug 2004 09:14:06 GMT  
 creating word mailing labels with Mail Merge
Hi, Julin,

I think your idea about a problem with the ActiveDocument is correct. I believe
that after the .CreateNewDocument statement, the ActiveDocument object refers to
the one that you have just created -- that is, the ActiveDocument object no
longer refers to the main merge document. That's why you're getting an error
message that says (in English translation) that the main merge document does not
contain merge fields.

I think you should try something like this:

  Private Sub cmdWord_Click()
  Dim w As New Word.Application
  Dim oDoc as Word.Document
  Set oDoc = w.Documents.Add

Then in the rest of your macro, replace w.ActiveDocument with oDoc. Then oDoc
will refer to the same document, the main merge document, throughout the macro,
even though some other document may become the ActiveDocument.

At the end of the macro, where you set w = Nothing, you should also set oDoc =
Nothing.

--
Regards,
Jay Freedman
Microsoft Word MVP        Word MVP FAQ site: http://www.mvps.org/word


Quote:
> I cant find the problem, the merge fields in the main merge document  match
> the field names in Access. I have created a new Data Base with new tables
> and it doesnt run. So i send you the code. It is maybe a problem with the
> ActiveDocument at the moment running .Execute but i cant resolve it.

> Private Sub cmdWord_Click()
> Dim w As New Word.Application
> w.Documents.Add

> w.ChangeFileOpenDirectory (App.Path)
> w.ActiveDocument.SaveAs FileName:="VBASample_" & _
>  ".doc", _
> FileFormat:=wdFormatDocument, _
> LockComments:=False, Password:="", _
> ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
> SaveNativePictureFormat:=False, SaveFormsData:=False, _
> SaveAsAOCELetter:=False

>   w.ActiveDocument.MailMerge.MainDocumentType = wdMailingLabels

>   w.ActiveDocument.MailMerge.OpenDataSource Name:= _
>         App.Path & "\julian.mdb", _
>         ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
>         AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="",
> _
>         WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False,
> _
>         Format:=wdOpenFormatAuto, Connection:="TABLE julian", SQLStatement:=
> _
>         "SELECT Nombre, Dni FROM [julian]", SQLStatement1:=""

>   w.Application.MailingLabel.DefaultPrintBarCode = False
>   'w.Application.MailingLabel.CreateNewDocument

>   w.Application.MailingLabel.CreateNewDocument Name:="2160 mini", Address:=
> _
>         "Nombre: ?Nombre?" & Chr(13) & "dni: ?Dni?" & Chr(13), AutoText:="",
> _
>         LaserTray:=wdPrinterManualFeed

>     If ActiveDocument.MailMerge.State = wdMainAndDataSource Then
>     With w.ActiveDocument.MailMerge

>         .Destination = wdSendToNewDocument
>         .MailAsAttachment = False
>         .MailAddressFieldName = ""
>         .MailSubject = ""
>         .SuppressBlankLines = True
>         With .DataSource
>            .FirstRecord = wdDefaultFirstRecord
>            .LastRecord = wdDefaultLastRecord
>         End With
>         .Execute pause:=True 'this method is not implemented in the active
> document

>     End With
>     End If
>     w.ActiveDocument.SaveAs FileName:="etiquetas.doc", FileFormat:= _
>         wdFormatDocument, LockComments:=False, Password:="",
> AddToRecentFiles:= _
>         True, WritePassword:="", ReadOnlyRecommended:=False,
> EmbedTrueTypeFonts:= _
>         False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
>         SaveAsAOCELetter:=False

> 'crea las etiquetas************************************************

> 'cierra el documento sin guardar los cambios

> w.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges

> 'termina la aplicacin Word
> w.Application.Quit

> Set w = Nothing
> End Sub


> > [Posting email response. Please keep all replies in the newsgroup so that
> others
> > can follow.]

> > Hi, Julin,

> > That error isn't one I'm familiar with (when I check it in Word VBA, it
> says
> > it's an "Application-defined or object-defined error"). But what I suspect
> is
> > that the merge fields in the main merge document don't match the field
> names in
> > Access. This may be because of a spelling error in the merge fields, or
> because
> > the merge document is not properly opened, or because there's something
> wrong
> > with the Access database.

> > --
> > Regards,
> > Jay Freedman
> > Microsoft Word MVP        Word MVP FAQ site: http://www.mvps.org/word

> > "julin atienza" replied:

> > >The error is :

> > >-Error "4605" in executing time:

> > >this method or property is not available because The principal active

> > >document of combination of correspondence does not have combination

> > >fields- If i remove pause:=True the program fails with the same error;

> > >and if i remove all the sentence

> > >-ActiveDocument.MailMerge.Execute pause:=True -

> > >it creates a Word document with mailing labels fields empty-it doesnt

> > >read any data from Access-.



> > > Hi, julin,

> > > What is the exact wording of the error message when it fails? Does it
> help to
> > > remove the "pause:=True" part?

> > > --
> > > Regards,
> > > Jay Freedman
> > > Microsoft Word MVP        Word MVP FAQ site: http://www.mvps.org/word



> > > > Im trying to create Word  mailing labels with Mail Merge.
> > > > I ve just copied the code generated by recording a Word macro; but
> when i
> > > > execute the macro it produces an error at line
> > > > "ActiveDocument.MailMerge.Execute pause:=True"
> > > > I cant understand why it fails here. Could anybody help me?
> > > > thanks a lot.



Fri, 20 Aug 2004 10:38:21 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Word Mail Merge Err - Word could not merge...

2. HTML forms, Word, e-mail and mail merge

3. HTML forms, Word, e-mail and mail merge

4. Mail Merge BarCodes / Mail Merge Insertion Point

5. Creating a mail merge file for importing into Word

6. Create Form Letter in Word 97 without using Mail Merge

7. Formatting Merge Fields in Word Mail Merge

8. using VBA for label mail merge

9. Help sending HTML mail in mail merge

10. Attachments for e-mail in mail merge

11. Sending mail in RTF whiteout using mail merge?

12. Access/Word mail merge

 

 
Powered by phpBB® Forum Software