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.
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.
> 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.