473,396 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

invalid use of null in mail merge function

Lee
Hello all,

As usual I've managed to copy a function I found on the Internet into my
application and get it to partially work. The problem is that when Access
encounters a field which is empty, it gives me the message "invalid use of
null"-- for example, if the FirstLastName field is empty for a record....
Can someone please tell me what I need to add to the function to allow use
of null values? Here's part of the function below.

Thanks alot!
Lee
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]))
Nov 12 '05 #1
3 3834
On Sun, 18 Apr 2004 21:25:39 -0400, "Lee" <lr*************@cox.net>
wrote:
Hello all,

As usual I've managed to copy a function I found on the Internet into my
application and get it to partially work. The problem is that when Access
encounters a field which is empty, it gives me the message "invalid use of
null"-- for example, if the FirstLastName field is empty for a record....
Can someone please tell me what I need to add to the function to allow use
of null values? Here's part of the function below.

Thanks alot!
Lee
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]))


You mention in your introduction that an error would occur "if the
FirstLastName field is empty for a record". However, you aren't
accessing the FirstLastName field above. So your request is somewhat
confusing.

However, look into the Nz(....) function. Wherever you have
FirstLastName you might consider using Nz(FirstLastName,"")

mike
Nov 12 '05 #2


Mike,

You're right. The field name is "name", while the bookmark name is
"firstlastname".

Thanks for the suggestion to use the nz() function. Could you show me
specifically how to write this into my code? Sorry to be a bother, but
VBA is very counterintuitive for me (I'm not a programmer, just an
average Joe in over my head)and I'm not sure what to do with this
function.

Thanks again.

Lee

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #3
On 19 Apr 2004 19:37:26 GMT, Lee Rouse <le********@yahoo.com> wrote:


Mike,

You're right. The field name is "name", while the bookmark name is
"firstlastname".

Thanks for the suggestion to use the nz() function. Could you show me
specifically how to write this into my code? Sorry to be a bother, but
VBA is very counterintuitive for me (I'm not a programmer, just an
average Joe in over my head)and I'm not sure what to do with this
function.


You'll have to post your existing code to get more than what I've
already said (see prior post), because what I already said gives you
explicit instructions on what to replace and what to replace it with.

As an aside, you generally don't want to use reserved words for things
that you name yourself. Hence, don't use "Name" as the name of
anything. You might use txtName as the name of a textbox, for
example, or tblName for the name field in a table.

mike

Nov 12 '05 #4

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

Similar topics

0
by: Lee | last post by:
Hello all, As usual I've managed to copy a function I found on the Internet into my application and get it to partially work. The problem is that when Access encounters a field which is empty,...
2
by: Aaron | last post by:
hello, i am perfoming a mail merge with the following code. Public Function MergeIt() Dim objWord As Object Set objWord = GetObject("C:\MyMerge.doc", "Word.Document") ' Make Word visible....
8
by: Squirrel | last post by:
Hi everyone, I've created a mail merge Word doc. (using Office XP) , the data source is an Access query. Functionality I'm attempting to set up is: User sets a boolean field to true for...
9
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...
3
by: Andy Davis | last post by:
I have set up a mail merge document in Word 2003 which gets its data from my Access 2000 database. I want to set up a button on a form that: 1. runs the query to provide the dat for the merge...
0
by: Phil C. | last post by:
Hi, I'm using Access 2000. I have a Select Query that uses the MID function to separate the actual text of articles from the title of the articles. The articles are enterd into the...
1
by: John Welch | last post by:
I'm trying to use the Mergit() function from the MS Knowledge base article to merge data from a query or table in my Access 2000 mdb into an existing word merge document. Every time it runs it...
1
by: Esther Lane | last post by:
Hello! First off, many many thanks to Albert who wrote the Mail Merge code for MS Access I am using. It has been working beautifully for a few years. However, my client just (without notice!)...
1
by: kayberrie | last post by:
I want to write a VBA mail merge code. I want to link the code/macro/dohicky to a nifty little button so it makes life easy. I think I can handle the button part, the code part - not so much. I know...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...

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.