mail merge - clarification

GaryPanic

Smoke me a Kipper,Skipper
Local time
Today, 04:51
Joined
Nov 8, 2005
Messages
3,309
I have super easy word merge - but I need an alternative - so looking at hte below (Pinched from samples)
question ....
" .Goto what:=wdGoToBookmark, Name:="Address1"
.TypeText [Address1]"
so the merge goes along hits Address1 in word and replaces it with Address1 from Access right ?
now if I want to duplication Address1 will it throw a tantrum or should i rename Address1 in word to say Address1a and then let access merge into it - ..(two qestions really)

(why two version you might ask- well super easy merge is going to be for letters - - hard mail merge will be for approved docs - I need to seperate them out - so wording - contracts on the merge - super easy for covering letters ( there are upto 50 contracts and 50 or so wordings - mainly th eams ebut with tweaks that have been approved and signed off by contract lawyers )

cod ebelow

Private Sub cmdSend_Click()
' Check for empty fields and unsaved record.
If IsNull(FirstName) Then
MsgBox "First name cannot be empty"
Me.FirstName.SetFocus
Exit Sub
End If
If IsNull(LastName) Then
MsgBox "Last name cannot be empty"
Me.LastName.SetFocus
Exit Sub
End If
If IsNull(Address1) Then
MsgBox "First line of address cannot be empty"
Me.Address1.SetFocus
Exit Sub
End If

If Me.Dirty Then
If MsgBox("Record has not been saved. " & Chr(13) & _
"Do you want to save it?", vbInformation + vbOKCancel) = vbOK Then
DoCmd.RunCommand acCmdSaveRecord
Else
Exit Sub
End If
End If

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

' Specify location of template
strTemplateLocation = "C:\MailMerge\AccessToWord.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:="recipient"
.TypeText Trim([Title] & " " & [FirstName] & " " & [LastName])

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

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

.Goto what:=wdGoToBookmark, Name:="Address3"
If IsNull(Address3) Then
.EndOf Unit:=wdParagraph, Extend:=wdExtend
.TypeBackspace
Else
.TypeText [Address3]
End If

.Goto what:=wdGoToBookmark, Name:="PostCode"
If IsNull(PostCode) Then
.EndOf Unit:=wdParagraph, Extend:=wdExtend
.TypeBackspace
Else
.TypeText [PostCode]
End If

.Goto what:=wdGoToBookmark, Name:="Country"
' If recipient in own country, no need to state country in letter.
If IsNull(Country) Or Country = "Canada" Then
.EndOf Unit:=wdParagraph, Extend:=wdExtend
.TypeBackspace
Else
.TypeText [Country]
End If

.Goto what:=wdGoToBookmark, Name:="Salutation"
.TypeText [FirstName]
End With

DoEvents
WordApp.Activate

Set WordApp = Nothing
Exit Sub

ErrHandler:
Set WordApp = Nothing

End Sub
 
" .Goto what:=wdGoToBookmark, Name:="Address1"
.TypeText [Address1]"
so the merge goes along hits Address1 in word and replaces it with Address1 from Access right ?
A Word bookmark can only exist once for one place. So as far as I know you cannot have 2.

I would suggest you look at the examples here. I learnt everything I know about Word automation there.

http://www.helenfeddema.com/

Instead of bookmarks I add Word Document Properties to my precedent Word docs and then add the information from access by referring to these Properties.
 
OK I have been thrash this around for a bit and have kind a got it - however on the below...
I have a field called postcode - yet on the merge it has the word PostCode instead of a blank (I know it should be a blank on this record)

Is I dim or am I missing the plot ..


.Goto what:=wdGoToBookmark, Name:="PostCode"
If IsNull(Postcode) Then
.EndOf Unit:=wdParagraph, Extend:=wdExtend
.TypeBackspace
Else
.TypeText [Postcode]
End If
 

Users who are viewing this thread

Back
Top Bottom