It might not have anything to do with the problem, but why are you calling
the Add method of the Bookmarks collection? You've already assigned text to
an existing bookmark of that name.
FWIW here's some code I use for addressing a template letter with values
from an Access form. It was developed in Access 2002 but the application has
been distributed to Office 2003 users and I've had no re[orts of any
problems. The path to the Word template document is passed into the
CreateLetter procedure as its argument:
''''module begins''''
Option Compare Database
Option Explicit
Sub CreateLetter(strTemplate As String)
' Opens a document in Word and inserts values from
' current record at bookmarks in Word document.
' Accepts: path to Word template file - String
On Error GoTo Err_Handler
Dim objWord As Object
Dim objDoc As Object
Dim frm As Form
Dim strAddress As String
' return reference to form
Set frm = Forms!frmAddresses
' if Word open return reference to it
' else establish reference to it
On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If Err.Number = 429 Then
Set objWord = CreateObject("Word.Application")
End If
AppActivate "Microsoft Word"
On Error GoTo Err_Handler
' open Word document in maximised window
objWord.Visible = True
Set objDoc = objWord.Documents.Add(strTemplate)
objWord.WindowState = wdWindowStateMaximize
' insert text at bookmarks, getting values from form
InsertAtBookmarks objWord, objDoc, "FirstName", frm!FirstName
InsertAtBookmarks objWord, objDoc, "LastName", frm!LastName
strAddress = (frm!Address + vbNewLine) & (frm!Address2 + vbNewLine) & _
(frm!City.Column(1) + vbNewLine) & (frm!County + vbNewLine) &
frm!PostCode
InsertAtBookmarks objWord, objDoc, "Address", strAddress
InsertAtBookmarks objWord, objDoc, "CurrentDate", Format(VBA.Date(), "d
mmmm yyyy")
InsertAtBookmarks objWord, objDoc, "ToName", frm!FirstName
Set objDoc = Nothing
Set objWord = Nothing
Exit_here:
On Error GoTo 0
Exit Sub
Err_Handler:
MsgBox Err.Description & " (" & Err.Number & ")"
Resume Exit_here
End Sub
Private Sub InsertAtBookmarks(objW As Object, _
objD As Object, _
strBookmark As String, _
varText As Variant)
' select bookmark
objD.Bookmarks(strBookmark).Select
' insert text at bookmark
objW.Selection.Text = Nz(varText, "")
End Sub
''''module ends''''
Ken Sheridan
Stafford, England
MSU Sptn2 said:
I created an automation to send data from an Access table to Word 2000 using
bookmarks in Word. Some of the computers on the server have Word 2003 and
the code does not work. I think the problem lies in the following code:
.ActiveDocument.Bookmarks("App_No").Select
If [Form_ODDAPP FORM].[App No] <> 1 Then
.Selection.Text = (CStr([Form_ODDAPP FORM].[App No]))
Else
.Selection.Text = .Selection.Text & (CStr(""))
End If
.ActiveDocument.Bookmarks.Add name:="App_No", Range:=Selection.Range
Is there something in the code that is not compatible with Word 2003? It
works smoothly with Access 2000 and Word 2000 but not Word 2003.
Thanks