By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,493 Members | 1,351 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,493 IT Pros & Developers. It's quick & easy.

invalid use of null in mail merge function

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a


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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.