Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run a Query from Form which feeds a mail merge

Status
Not open for further replies.

encodeme

Programmer
Joined
Jul 8, 2005
Messages
14
Location
PT
I have 2 tables, Customers and Information linked by a common field Linknumber.

They both have a form. Customers is the main form, and Information is a sub form of Customers.

A query called Blended Query takes the data from both tables

On the sub form is a Command button that starts a Macro.

The Macro calls the Function below which creates a Mailmerge for each customer in Word .

Function MergeIt1()
Dim objWord As Word.Document
Set objWord = GetObject("C:\Documents and Settings\ My Documents\Ron\ Database\Rental.doc", "Word.Document")
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source as the Bollo database.
objWord.MailMerge.OpenDataSource _
Name:="C:\Documents and Settings\My Documents\Ron\ Database\Bollo.mdb", _
LinkToSource:=True, _
Connection:="QUERY blended query", _
SQLStatement:="SELECT * FROM [blended query]"
' Execute the mail merge.
objWord.MailMerge.Execute

End Function

I would like to restrict the data in the query to that of the open Form only, so that the mail merge creates only for that customer.

Also is there any way of stopping the warning message in Word when the SQL statement is about to run. It requires a Yes or No choice to be made.
 
many thanks Mr Merlotti.
I found and sorted the security warning fix, but am not sure about the Where clause in the statement.
I imagine it should read on the lines of
SQLStatement:="SELECT * FROM [blended query]"WHERE tblCustomer.lastname= FormCustmers.lastname.

Aas yet Iam truly a SQL novice.
thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top