invalid use of null in mail merge function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lee

    invalid use of null in mail merge function

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


  • Mike Preston

    #2
    Re: invalid use of null in mail merge function

    On Sun, 18 Apr 2004 21:25:39 -0400, "Lee" <lrouse2REMOVEM E@cox.net>
    wrote:
    [color=blue]
    >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 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]))[/color]

    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(FirstLastNam e,"")

    mike

    Comment

    • Lee Rouse

      #3
      Re: invalid use of null in mail merge function



      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 counterintuitiv e 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!

      Comment

      • Mike Preston

        #4
        Re: invalid use of null in mail merge function

        On 19 Apr 2004 19:37:26 GMT, Lee Rouse <leemodeler@yah oo.com> wrote:
        [color=blue]
        >
        >
        >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 counterintuitiv e 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.[/color]

        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

        Comment

        Working...