Creating Merge Template

infinitx

Registered User.
Local time
Today, 08:12
Joined
Mar 22, 2004
Messages
63
Hi,

I tried to create this document template:

CaseText

ItemText

But everythime I click the button in access, the template opens, but it contains this:

CaseText

ItemText

In other words, it does not change the preset values.

Here's the code I am using:

' Check for empty fields and unsaved record.
If IsNull(ItemsTable_Item_Text) Then
MsgBox "First name cannot be empty"
Me.ItemsTable_Item_Text.SetFocus
Exit Sub
End If
If IsNull(CaseTable_Case_Text) Then
MsgBox "Last name cannot be empty"
Me.CaseTable_Case_Text.SetFocus
Exit Sub
End If

' Create a Word document from template.
Dim WordApp As Word.Application
Dim strTemplateLocation As String

' Specify location of template
strTemplateLocation = "C:\Test.dot"


On Error Resume Next
Set WordApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set WordApp = CreateObject("Word.Application")
End If
On Error GoTo ErrHandler


WordApp.Visible = True
WordApp.WindowState = wdWindowStateMaximize
WordApp.Documents.Add Template:=strTemplateLocation, NewTemplate:=False

' Replace each bookmark with field contents.
With WordApp.Selection


.Goto what:=wdGoToBookmark, Name:="ItemText"
.TypeText [ItemsTable_Item_Text]

.Goto what:=wdGoToBookmark, Name:="CaseText"
' If Address2 is empty, remove the line.
If IsNull(CaseTable_Case_Text) Then
.EndOf Unit:=wdParagraph, Extend:=wdExtend
.TypeBackspace
Else
.TypeText [CaseTable_Case_Text]
End If

End With

DoEvents
WordApp.Activate

Set WordApp = Nothing
Exit Sub

ErrHandler:
Set WordApp = Nothing

End Sub

What is wrong?

Thanks in advance!
 
Presuming you have bookmarks called CaseText and ItemText (not just the words), I don't see anything wrong.
 

Users who are viewing this thread

Back
Top Bottom