In my DB, how do I link to the table named DAVID. Right now, Word asks for the table, and presents a list of all the tables in MyDB.
Thanks.
Printable View
In my DB, how do I link to the table named DAVID. Right now, Word asks for the table, and presents a list of all the tables in MyDB.
Thanks.
David, is your "DAVID" table in the list that is presented?
yes. i see the connection: object. i think that's it
hmm. it is still asking. oops. changed the wrong one. :blush:
Plus, I don't want to be prompted to save the .dot file. How do i do that?
Oops. I still need help. I said the Connection was "Table David"
and it still asks!
Where is the code you were using?
When you open the template in code you can specify readonly, I think, and
in the close method you can specify False as the save changes argument.
VB Code:
Dim oDoc As Word.Document moApp.Visible = True Set oDoc = moApp.Documents.Add("D:\Test.dot", , , True) With oDoc.MailMerge .MainDocumentType = wdFormLetters .OpenDataSource Name:="D:\RobDog888.mdb", LinkToSource:=True, Connection:="TABLE ClientData" End With With oDoc.MailMerge.DataSource .FirstRecord = 1 .LastRecord = 20 End With With oDoc.MailMerge .Destination = wdSendToPrinter 'wdSendToNewDocument; wdSendToFax; wdSendToEmail .Execute True End With
I need a CLOSE statement also. Do I have to specify the first and last record? If I create a document, how do I close that by giving it a static name?
Well, it needs the SQL statement. http://support.microsoft.com/kb/289830
OK. One down, and three to go.
I need a CLOSE statement also.
Do I have to specify the first and last record?
If I create a document, how do I close that by giving it a static name?
Thanks.
We have set a document object equal to the instance of "Document1". so we can
close just that document any time we want like this.
VB Code:
Option Explicit Private Sub Command1_Click() Dim oDoc As Word.Document moApp.Visible = True Set oDoc = moApp.Documents.Add("D:\Test.dot", , , True) With oDoc.MailMerge .MainDocumentType = wdFormLetters .OpenDataSource Name:="D:\RobDog888.mdb", LinkToSource:=True, Connection:="TABLE ClientData" End With With oDoc.MailMerge.DataSource 'If you want to specify a range of records .FirstRecord = 1 .LastRecord = 20 End With With oDoc.MailMerge .Destination = wdSendToPrinter 'wdSendToNewDocument; wdSendToFax; wdSendToEmail .Execute True End With oDoc.Close False Set oDoc = Nothing moApp.Quit Set moApp = Nothing End Sub
1) It won't let me comment out the range for first and last doc. I tried to comment out the 4 lines (including the with)
2) Doc 2 (the merged document is still left open if i choose mergetonewdoc. should i leave it open?
VB Code:
With oDoc.MailMerge.DataSource ' .FirstRecord = 1 ' .LastRecord = 3 ' End With ' With oDoc.MailMerge .Destination = wdSendToPrinter 'wdSendToNewDocument;wdSendToPrinter; wdSendToFax; wdSendToEmail ' .Destination = wdSendToNewDocument 'wdSendToNewDocument;wdSendToPrinter; wdSendToFax; wdSendToEmail .Execute True End With ' oDoc.Close False Set oDoc = Nothing moApp.Quit Set moApp = Nothing
You can attach a document object to the merge result document or you can reference it by name
in the documents collection. For the range you can use you ADO recordset recordcount as the last
record unless you only need a few records. If you are printing directly then close the docs. If you
are emailing automatically then close else leave, etc.
:)
I did a special query to get the record count previously, and placed it in another table. Is there an easier way? I have a sql string to get the records as * from David. Is there a way to get the count then?
I'm not sure that I follow you about the object, or Document collection.
Would I just use Document 2 for the merged document? How to refer to it by name? (It seems to be called Letter2, and just 2 when I save it)
Thanks for the help...
VB Code:
Option Explicit Private Sub Command1_Click() Dim oDoc As Word.Document Dim oMMDoc As Word.Document moApp.Visible = True Set oDoc = moApp.Documents.Add("D:\Test.dot", , , True) With oDoc.MailMerge .MainDocumentType = wdFormLetters .OpenDataSource Name:="D:\RobDog888.mdb", LinkToSource:=True, Connection:="TABLE ClientData" End With With oDoc.MailMerge.DataSource 'If you want to specify a range of records .FirstRecord = 1 .LastRecord = .RecordCount End With With oDoc.MailMerge .Destination = wdSendToPrinter 'wdSendToNewDocument; wdSendToFax; wdSendToEmail .Execute True End With oDoc.Close False 'Either method shoud work depending that the documents collection only had the template and the mm doc 'also if you dont need to do anything with it then the one liner would be best 'moApp.Documents(1).Close False 'Method two 'Set oMMDoc = moApp.Documents(1) 'oMMDoc.Close False 'Set oMMDoc = Nothing Set oDoc = Nothing moApp.Quit Set moApp = Nothing End Sub
that looks real good. thanks.
No prob. ;)
Ps, I dont like using MM's so I appologise for the limited examples. Guess if I
was more into them I could do more.
Later