473,812 Members | 2,947 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 CreateWordLette r(strDocPath As String)

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

If IsNull(strDocPa th) 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("W ord.Application ")

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

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

.activedocument .Bookmarks("Par entsGuardian"). Select
.Selection.Text =
(CStr(Forms![frmmergeIFSP]![ParentsGuardian]))

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

End With
'release all objects

Set dbs = Nothing
End Function
Nov 12 '05 #1
1 2014
On 19 Apr 2004 07:40:04 -0700, le********@yaho o.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 CreateWordLette r(strDocPath As String)

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

If IsNull(strDocPa th) 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("W ord.Application ")

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

..Documents.Add Template:=strDo cPath

mike

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

.activedocument .Bookmarks("Par entsGuardian"). Select
.Selection.Text =
(CStr(Forms![frmmergeIFSP]![ParentsGuardian]))

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

End With
'release all objects

Set dbs = Nothing
End Function


Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4832
by: louise | last post by:
hi i am trying to set up a mail merge button which takes records from a multi-select listbox (the contents of which are decided by a query created by a search from) and not from a specific query. I have a function GetCriteria() Private Function GetCriteria() As String Dim stDocCriteria As String
2
2513
by: Bob Hynes | last post by:
Hi All, This code is running in WinNT/Access97. I'm looking for some help with getting this code to do two(2) things better then it does now and I'm not sure how to do it. 1. On the 'objWord.Application.Quit' statement, it asks if I want to save changes and I would like it to not ask that and I don't know what the exact code is to do that. 2. On the 'objWord.MailMerge.Execute' statement the printer dialog window pops up and I have to...
1
3138
by: Lisa | last post by:
I have a query named QryDept where one of the fields is DeptID. The query is used for the data source of a mail merge letter. I would like to control which department is to get the mail merge letters. I have a department selection pop-up form where the departments are listed in a listbox. The value of the listbox is DepartmentID. On the form is a Create Mail Merge button which is coded to open the mail merge and make the pop-up form not...
0
1523
by: Lauren Wilson | last post by:
Hi folks, I am using the following code to merge data from an Access table to a pre-defined Word 2000 merge document. It al works fine except for ONE problem -- after the merged document displays and the user saves it or whatever, then closes it, the actual merge template is displayed in the background and asks if the user wants to save the updated merge document. I do not want the user to even be aware of the merge template at all. ...
9
4331
by: Neil Ginsberg | last post by:
I have a strange situation using Access to automate a Word mail merge. Using Access 2000 and Word 2000, the code opens Word, opens the document in Word, sets a table in the calling Access application as the data source, and then performs a merge. Everything works fine. However, when a user uses it in Access 2002 and Word 2002, an extra instance of the Access application is opened and remains open at the end. Sometimes it remains open
3
5511
by: ljungers | last post by:
I need to make some changes to a Query/select/print report using word application. What I need to do is change the way Word is called yet keep the process the same. Word is used so changes can be made before actual printing. Need some way of calling Word as a mail merge with the information from an Access table that the current report uses. I have seen mail merge templates that use something like <<field name>> in them that uses a table....
9
2375
by: atc | last post by:
Sorry but another question from a newbie. I am trying to create a mail merge based on a query. I have a button on a form (form is based on query). I found this code in one of the discussions and tried to modify it for my needs. Private Sub Command36_Click() Set objWord = GetObject("C:\Documents and Settings\xxxx\My Documents\merge.doc", "Word.Document") 'turn off alerts objWord.Application.DisplayAlerts = wdAlertsNone ' Make Word...
7
4170
by: =?Utf-8?B?QmFkaXM=?= | last post by:
Hi, I'm trying to follow a mail merging example in C#.Net that I got from: http://support.microsoft.com/default.aspx/kb/301659 and in one the methods: Word.Application wrdApp; Word._Document wrdDoc; Object oMissing = System.Reflection.Missing.Value; Object oFalse = false;
1
1698
by: =?Utf-8?B?VHJ1cHRpIERhbGlh?= | last post by:
Hi to all, I am new in this newsgroup and new to .NET also. I am creating an application where I have to perform Mail Merge from my program. I have created a form which contain RTB and user can write letters. I programmatically add tags for address, name, comp. name et while saving the letter. I have a datasource - in for mof a dataset to whom I have to send the letter. This is where I am stuck. I don't know how to open the selected...
0
995
by: truptidalia | last post by:
Hi, I am not that experienced in VB.NET. I am working on a application where i have to perform mail merge from the application. The application lets the userwrite letters, save them as rtf file. In letter, tags are added programmatically for fields to add data while merging. User can use the letter later to perform mail merge on it to selected customers. Customers dataset is ready. Now, can any one assist me how to move further to...
0
9734
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10664
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10404
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9219
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7677
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6897
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5704
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3881
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3029
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.