Thread: [Solved] Listbox showing null
View Single Post
 
Old 03-14-2020, 07:29 PM
JustLearnin JustLearnin is offline Windows 10 Office 2019
Novice
 
Join Date: Mar 2020
Posts: 5
JustLearnin is on a distinguished road
Default Listbox showing null

I have created two list boxes in word VBA. The first Listbox1 when an item is selected it will add an item to the second list box.

The second list box should then use that value as a bookmark.

The error I get is that Listbox2 shows the text but not the value. So when I refer to that Listbox2 is states "ListBox2.value = "" (null or nothing). How do I get this value?


Here is the bit of code that I wrote.
Private Sub ListBox2_Enter()
Dim sMyStr As String
sMyStr = Me.ListBox1.Value
If sMyStr = "P21" Then
ListBox2.AddItem "41"
ElseIf sMyStr = "P69" Then
ListBox2.AddItem "31"
ElseIf sMyStr = "P62" Then
ListBox2.AddItem "11"
ElseIf sMyStr = "P64" Then
ListBox2.AddItem "42"
Else
ListBox2 = ""
End Sub


Many thanks in advance for any assistance.
Reply With Quote