PDA

View Full Version : [SOLVED:] Run Time Error 94 - Invalid use of Null



Iris
01-26-2015, 08:13 PM
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
12757


Please let me know if you need any further information.

Thank you

gmayor
01-26-2015, 11:21 PM
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?

Iris
01-27-2015, 03:50 AM
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

gmayor
01-27-2015, 05:34 AM
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.

Iris
01-31-2015, 06:04 PM
Thank you so much for your help. Very much appreciated.