Hello i've read this thread :http://www.vbforums.com/showthread.php?t=575528 and when i try to execute this code with the modifications to my DB and my DOC document what happens is as soon as i click to generate the file it asks for me the table i choose the right one and the document opens and closes too quickly I know that is from 2009 but isn't there any updated or working one? Thanks
In case you need it:
Code:
Private Sub cmdGerar_Click()
Dim oApp As Word.Application
Dim oDoc As Word.Document
Dim oMerge As Word.MailMerge
Dim oResult As Word.Document
Set oApp = CreateObject("Word.Application")
'Open a Word MailMerge document
Set oDoc = oApp.Documents.Add("C:\Documents and Settings\dream\Ambiente de trabalho\SÉRGIO SOARES ESTÁGIO\CNO\Relatorios\acta_individual.doc", False, wdNewBlankDocument, False)
'Instanciate a MailMerge object
Set oMerge = oDoc.MailMerge
With oMerge
'Set the source where your data will be coming from
.OpenDataSource "C:\Documents and Settings\dream\Ambiente de trabalho\SÉRGIO SOARES ESTÁGIO\CNO\cno.mdb"
'Specify the output destination. ie: a new document or a printer etc
.Destination = wdSendToNewDocument 'OR wdSendToPrinter if you just want to print
.Execute
End With
'Do stuff with the document if you want via the oResult document object
Set oResult = oApp.ActiveDocument 'This is your merged document (if shown).
'You can show the document if you are going to allow the use to edit or ???
oApp.Visible = True
'...
'Close and release ref'd objects saving them if you want by changing the argument to True
oResult.Close SaveChanges:=False
Set oResult = Nothing
Set oMerge = Nothing
oDoc.Close SaveChanges:=False
Set oDoc = Nothing
oApp.Quit SaveChanges:=False
Set oApp = Nothing
End Sub