Mail Merge with word

  • Thread starter Thread starter Simon
  • Start date Start date
S

Simon

I have a button on my form that opens up a word file that then mail
merges with some of the data in my database


evey time i run this query it automaticaly askes if i want to open the
document and run the follwoung SQL command



Is there a way that i can set it up that it automaticly say yes???

Another small thing is once the work document is loaded i have to press
merge and print button. Is there a way to do this automaticaly


Thanks

Simon
 
i have tried to get the code to work but having problems

can u see what would be wrong

Function MergeIt()
Dim objWord As Word.Document
Set objWord = GetObject("C:\Documents and Settings\Simon\My
Documents\Hot Tubs 2 Buy\Bro\Bro Letter Test.doc", "Word.Document")
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source as the Northwind database.
objWord.MailMerge.OpenDataSource _
Name:="C:\Documents and Settings\Simon\My Documents\Hot Tubs 2
Buy\Database\Hot Tubs 2 Buy sql.mdb", _
LinkToSource:=True, _
Connection:="Query qryBrochure", _
SQLStatement:="SELECT * FROM [qryBrochure]"
objWord.MailMerge.Destination = wdSendToNewDocument
objWord.MailMerge.Execute

'The following line must follow the Execute statement because the
'PrintBackground property is available only when a document window is
'active. Without this line of code, the function will end before Word
'can print the merged document.

objWord.Application.Options.PrintBackground = False
objWord.Application.ActiveDocument.PrintOut
End Function


]
 
Sorry but "Having problems" description doesn't help potential repondents to
work out what's wrong.

What is the result you get when you run the code?

If you get an error:

What is the error message (and error number if possible) you get?

Which line of code errors out?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top