Article ID: 124862
Article Last Modified on 10/11/2006
131583 ACC: Sending the Current Record to Word 97 with Automation
First Last
Address
City, Region, PostalCode
Dear Greeting,
Northwind Traders would like to thank you for
your employment during the past year. Below
you will find your photo. If this is not your
most current picture, please let us know.
Photo
Sincerely,
Northwind Traders
Dim Word As Object
In version 7.0:
Sub Command40_Click()
On Error GoTo CatchBlanks
Dim Word As Object ' Declare in the module to view the print
' preview after the Sub ends
DoCmd.GoToControl "Photo"
DoCmd.DoMenuItem acFormBar, acEditMenu, acCopy, , acMenuVer70
Set Word = CreateObject("Word.Basic")
Word.FileOpen ("C:\OLEMERGE.DOC")
Word.EditGoto "Last"
Word.INSERT CStr(Forms![Employees]![LastName])
Word.EditGoto "First"
Word.INSERT CStr(Forms![Employees]![FirstName])
Word.EditGoto "Address"
Word.INSERT CStr(Forms![Employees]![Address])
Word.EditGoto "City"
Word.INSERT CStr(Forms![Employees]![City])
Word.EditGoto "Region"
Word.INSERT CStr(Forms![Employees]![Region])
Word.EditGoto "PostalCode"
Word.INSERT CStr(Forms![Employees]![PostalCode])
Word.EditGoto "Greeting"
Word.INSERT CStr(Forms![Employees]![FirstName])
Word.EditGoto "Photo"
Word.EditPaste
'Word.FilePrint 0
' To send the record directly to the printer, unremark the line
' above, and remark the next two lines below.
Word.appmaximize "",1
Word.FilePrintPreview
Word.AppActivate "Microsoft Word"
Exit Sub
CatchBlanks:
If MsgBox("Error sending one field, it may be blank. Would _
you like to continue?", 52) = 6 Then
Resume Next
Else
Exit Sub
End If
End Sub
In version 2.0:
NOTE: In the following sample code, an underscore (_) at the end of a line is used as a line-continuation character. Remove the underscore from the end of the line when re-creating this code in Access Basic.
Sub Button182_Click ()
On Error GoTo CatchBlanks
Dim Word As Object ' Declare in the module to view the print
' preview after the Sub ends
DoCmd GoToControl "Photo"
DoCmd DoMenuItem A_FORMBAR, A_EDIT, A_COPY
Set Word = CreateObject("Word.Basic")
Word.FileOpen ("C:\OLEMERGE.DOC")
Word.EditGoto "Last"
Word.Insert CStr(Forms![Employees]![Last Name])
Word.EditGoto "First"
Word.Insert CStr(Forms![Employees]![First Name])
Word.EditGoto "Address"
Word.Insert CStr(Forms![Employees]![Address])
Word.EditGoto "City"
Word.Insert CStr(Forms![Employees]![City])
Word.EditGoto "Region"
Word.Insert CStr(Forms![Employees]![Region])
Word.EditGoto "PostalCode"
Word.Insert CStr(Forms![Employees]![Postal Code])
Word.EditGoto "Greeting"
Word.Insert CStr(Forms![Employees]![Last Name])
Word.EditGoto "Photo"
Word.EditPaste
' Word.FilePrint 0, 0, "0", "", "", "", 0, "1", "", 0, 0, 1, ""
' NOTE: When sending the current record from Microsoft Access 2.0
' to Microsoft Word 95, replace the above line with the
' following line:
' Word.FilePrint 0
' To send the record directly to the printer, unremark one of the
' lines above, and remark the next two lines below.
Word.appmaximize "",1
Word.FilePrintPreview
Word.AppActivate "Microsoft Word"
Exit Sub
CatchBlanks:
If MsgBox("Error sending one field, it may be blank. Would _
you like to continue?", 52) = 6 Then
Resume Next
Else
Exit Sub
End If
End Sub
Word.Insert Cstr(Format(Forms![FormName]![Price], "Currency"))
Additional query words: editgoto mail
Keywords: kbhowto kbprogramming KB124862