Consulting

Results 1 to 5 of 5

Thread: Run Time Error 94 - Invalid use of Null

  1. #1
    VBAX Regular
    Joined
    Jan 2015
    Posts
    11
    Location

    Run Time Error 94 - Invalid use of Null

    Hi, I am trying to set up a letter in Word 2010 (Windows 8) and part of the form I have used a list box (Lenders) with multiple selections and I am trying to put this in a bookmark in the word document. When I try to run the program I am receiving the above error message. Can you please advise what is causing this error?

    Error message is occurring on this line - .Bookmarks("Lenders").Range.Text = ListBox1



    Option Explicit


    Private Sub Address_Change()


    End Sub


    Private Sub CommandButton1_Click()
    Address.Value = Null
    ListBox3.Value = Null
    TextBox1.Value = Null
    TextBox2.Value = Null
    TextBox3.Value = Null
    TextBox4.Value = Null
    TextBox5.Value = Null


    End Sub


    Private Sub CommandButton2_Click()
    With ActiveDocument
    .Bookmarks("Address").Range.Text = Address.Value
    .Bookmarks("Business").Range.Text = TextBox2.Value
    .Bo
    .Bookmarks("Name").Range.Text = TextBox3.Value
    .Bookmarks("Recipient").Range.Text = TextBox1.Value
    .Bookmarks("Title").Range.Text = TextBox4.Value
    End With
    Application.ScreenUpdating = True
    Unload Me

    End Sub


    Private Sub CommandButton3_Click()
    Unload Me
    ActiveDocument.Close SaveChanges:=False
    End Sub


    Private Sub Label1_Click()


    End Sub


    Private Sub ListBox1_Click()


    End Sub


    Private Sub ListBox3_Click()


    End Sub


    Private Sub TextBox1_Change()


    End Sub


    Private Sub TextBox2_Change()


    End Sub


    Private Sub TextBox4_Change()


    End Sub


    Private Sub UserForm_Click()


    End Sub


    Private Sub UserForm_Initialize()
    CommandButton2.Value = True
    With ListBox1
    .AddItem "Adelaide Bank"
    .AddItem "ANZ"
    .AddItem "Australian First Mortgage"
    .AddItem "Bank of Melbourne"
    .AddItem "Bank West"
    .AddItem "CBA"
    .AddItem "ING Direct"
    .AddItem "LaTrobe Financial"
    .AddItem "Liberty"
    .AddItem "NAB"
    .AddItem "St George"
    .AddItem "Westpac"
    End With
    End Sub
    Form.jpg


    Please let me know if you need any further information.

    Thank you

  2. #2
    Go advanced and attach your letter template so we can see the userform elements and your bookmarks.
    Your code refers to two list boxes Listbox1 and Listbox3?
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Regular
    Joined
    Jan 2015
    Posts
    11
    Location

    Run Time Error 94 - Invalid use of Null

    Attached is the letter template. I originally had two list boxes and removed list box 3, I have now removed from the code.

    I tried updating code to .Bookmarks("Lenders").Range.Text = ListBox1.Text, however received the error Run-time error 91 Object variable or with Variable not set.

    This is the first time I have used VBA so appreciate any help.

    Thank you
    Attached Files Attached Files

  4. #4
    The problems relate to the use of a multi-select list box.
    I have fixed the issues in the attached, allowing you to retain the multi-use function, and the ability to edit the document if you make a mistake, by re-running the main code.
    The document would be better saved as a template from which you should create new documents.
    Attached Files Attached Files
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  5. #5
    VBAX Regular
    Joined
    Jan 2015
    Posts
    11
    Location
    Thank you so much for your help. Very much appreciated.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •