469,936 Members | 2,422 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,936 developers. It's quick & easy.

need help with mail merge code

Hello,

I've been tweaking the code below to mail merge from Access 2000 to a
Word doc.

Two issues have come up.
1. The Code does not allow null values in any of the fields. Could
someone suggest what code to use so the function doesn't get hung up
on one or more fields? Please be specific- I know just enough about
vba to be dangerous to myself!

2.Data is merged with a .dot template file. When the data is merged, I
want the data to be merged with a new .doc, so that users don't
accidently save changes to the template. As it is now, the data is
merged into the .dot file. Can anyone help on this?

Thanks in advance,

Lee

Option Compare Database

Public Function CreateWordLetter(strDocPath As String)

'if no path is passed to function, exit - no further
'need to do anything

If IsNull(strDocPath) Or strDocPath = "" Then
Exit Function
End If

Dim dbs As Database
Dim objWord As Object
Set dbs = CurrentDb

'create reference to Word Object

Set objWord = CreateObject("Word.Application")

'Word Object is created
With objWord
.Visible = True
.Documents.Open (strDocPath)

'move to each bookmark, and insert text.
.activedocument.Bookmarks("FirstLastName").Select
.Selection.Text = (CStr(Forms![frmmergeIFSP]![Name]))

.activedocument.Bookmarks("ParentsGuardian").Selec t
.Selection.Text =
(CStr(Forms![frmmergeIFSP]![ParentsGuardian]))

.activedocument.Bookmarks("ChildSSN").Select
.Selection.Text = (CStr(Forms![frmmergeIFSP]![childssn1]))

End With
'release all objects

Set dbs = Nothing
End Function
Nov 12 '05 #1
1 1797
On 19 Apr 2004 07:40:04 -0700, le********@yahoo.com (Lee Rouse) wrote:
Hello,

I've been tweaking the code below to mail merge from Access 2000 to a
Word doc.

Two issues have come up.
1. The Code does not allow null values in any of the fields. Could
someone suggest what code to use so the function doesn't get hung up
on one or more fields? Please be specific- I know just enough about
vba to be dangerous to myself!
Asked and answered in another thread. Use the Nz() function.

2.Data is merged with a .dot template file. When the data is merged, I
want the data to be merged with a new .doc, so that users don't
accidently save changes to the template. As it is now, the data is
merged into the .dot file. Can anyone help on this?

Thanks in advance,

Lee

Option Compare Database

Public Function CreateWordLetter(strDocPath As String)

'if no path is passed to function, exit - no further
'need to do anything

If IsNull(strDocPath) Or strDocPath = "" Then
Exit Function
End If

Dim dbs As Database
Dim objWord As Object
Set dbs = CurrentDb

'create reference to Word Object

Set objWord = CreateObject("Word.Application")

'Word Object is created
With objWord
.Visible = True
.Documents.Open (strDocPath)
You want this line to be:

..Documents.Add Template:=strDocPath

mike

'move to each bookmark, and insert text.
.activedocument.Bookmarks("FirstLastName").Select
.Selection.Text = (CStr(Forms![frmmergeIFSP]![Name]))

.activedocument.Bookmarks("ParentsGuardian").Selec t
.Selection.Text =
(CStr(Forms![frmmergeIFSP]![ParentsGuardian]))

.activedocument.Bookmarks("ChildSSN").Select
.Selection.Text = (CStr(Forms![frmmergeIFSP]![childssn1]))

End With
'release all objects

Set dbs = Nothing
End Function


Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Bob Hynes | last post: by
9 posts views Thread by atc | last post: by
7 posts views Thread by =?Utf-8?B?QmFkaXM=?= | last post: by
1 post views Thread by =?Utf-8?B?VHJ1cHRpIERhbGlh?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.