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
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