ACC1x: Sending the Current Record to Word for Windows with DDEID: Q99570
|
This article describes how to send the current record in Microsoft Access
version 1.x to Microsoft Word version 2.0 or 6.0 for Windows to be merged
into a prewritten letter and printed.
This article assumes that you are familiar with dynamic data exchange
(DDE), setting bookmarks in Word for Windows, and creating modules and
using Access Basic in Microsoft Access.
CompanyName
Address
City, Region, PostalCode
Country
Dear ContactName,
Northwind Traders would like to thank you for
your business during the past year. Enclosed
you will find several samples of new products
that we are excited to announce.
Sincerely,
Northwind Traders.
Function Initiate_Word ()
Dim Chan As Variant
Dim WordTopics As Variant
Chan = StartApp("Winword", "System")
'StartApp is already in the NWIND database. To find it,
'Choose Modules, then Design in the Database Window.
'Choose StartUp from the Procedure list box
On Error GoTo AlertUser:
WordTopics = DDERequest(Chan, "Topics")
If InStr(1, WordTopics, "DDEMERGE.DOC") = 0 Then
DDEExecute Chan, "[FILEOPEN ""C:\DDEMERGE.DOC""]"
End If
DDETerminate Chan
Mergechan = DDEInitiate("Winword", "C:\DDEMERGE.DOC")
Exit Function
AlertUser:
MsgBox "MS Access is unable to initiate a DDE _
channel with the document DDEMERGE.DOC"
Resume Next
End Function
Function Send_Record ()
On Error GoTo CatchBlanks
DDEPoke Mergechan, "CompanyName",_
Forms![Customers]![Company Name]
DDEPoke Mergechan, "ContactName", _
Forms![Customers]![Contact Name]
DDEPoke Mergechan, "Address", _
Forms![Customers]![Address]
DDEPoke Mergechan, "City", _
Forms![Customers]![City]
DDEPoke Mergechan, "Region", _
Forms![Customers]![Region]
DDEPoke Mergechan, "PostalCode", _
Forms![Customers]![Postal Code]
DDEExecute Mergechan, "[FilePrint]"
Exit Function
CatchBlanks:
If MsgBox("Error sending one field, it may be blank._
Would you like to continue?", 52) = ID_YES Then
Resume Next
Else
Exit Function
End If
End Function
Function Terminate_MergeChan ()
DDETerminate MergeChan
End Function
Microsoft Access "Introduction to Programming," versions 1.0 and 1.1, Chapter 9, "Dynamic Data Exchange"
Additional query words: merge printmerge browse
Keywords : kbinterop
Version : 1.0 1.1
Platform : WINDOWS
Issue type : kbinfo
Last Reviewed: March 22, 1999