run time error '-2147467259 (80004005)' could not topindex property

MitchiBoy3

New Member
Joined
Feb 24, 2020
Messages
4
Office Version
  1. 2019
Platform
  1. Windows
Hi everyone!

I have this VBA form that have the functions of a search box. When I type a word in the search box , click (not double click) the word in the list box to highlight and trying to erase the word in the search box to change my search word, run time error will pop up. When I debug the error, it points to the list box code (bolded text). I get this code from a website with free use of the codes, credits to Mr. Gergely Gyetvai. I tried to contact the author, until now i have no reply received. Can some help me on this? thanks so much.


THE WHOLE CODE BELOW

------------------------------------------------------------------------
Option Explicit

Private Sub UserForm_Initialize()
'Load list during initalization
Call loadList
Me.tbox_srch_ID.SetFocus
End Sub

'------------------------------------------------

Private Sub cmd_add_Click()
Call addItemByClick
End Sub
Private Sub lbox_ID_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Call addItemByClick
End Sub

Private Sub lbox_Word_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Call addItemByClick
End Sub

Private Sub cmb_cancel_Click()
Unload Me
End Sub

'------------------------------------------------

Private Sub lbox_ID_Change()
Me.lbox_Word.ListIndex = Me.lbox_ID.ListIndex
Me.lbox_Word.TopIndex = Me.lbox_ID.TopIndex
End Sub

Private Sub lbox_Word_Change()
Me.lbox_ID.ListIndex = Me.lbox_Word.ListIndex
Me.lbox_ID.TopIndex = Me.lbox_Word.TopIndex
End Sub

Private Sub tbox_srch_ID_Keyup(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Me.tbox_srch_Word.Value = ""
Call loadList
End Sub

Private Sub tbox_srch_Word_Keyup(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Me.tbox_srch_ID.Value = ""
Call loadList
End Sub

' ----------------------------------------------------------------
Sub loadList()

Dim baseArray() As Variant
Dim resultArray() As Variant
Dim IDArray() As Variant
Dim wordArray() As Variant
Dim counter As Long, i As Long

On Error Resume Next

Me.lbox_ID.Clear
Me.lbox_Word.Clear

baseArray = WordList.Range("tbl_WordList")


counter = 0

For i = LBound(baseArray) To UBound(baseArray)
If ((InStr(1, baseArray(i, 1), Me.tbox_srch_ID.Value, vbTextCompare) > 0 And Me.tbox_srch_Word.Value = "") Or _
(InStr(1, baseArray(i, 2), Me.tbox_srch_Word.Value, vbTextCompare) > 0 And tbox_srch_ID.Value = "")) Then

counter = counter + 1

ReDim Preserve resultArray(1 To 2, 1 To counter)
resultArray(1, counter) = baseArray(i, 1)
resultArray(2, counter) = baseArray(i, 2)
End If
Next i

If counter > 0 Then
ReDim IDArray(1 To UBound(resultArray, 2), 1 To 1)
ReDim wordArray(1 To UBound(resultArray, 2), 1 To 1)

For i = LBound(resultArray, 2) To UBound(resultArray, 2)
IDArray(i, 1) = resultArray(1, i)
wordArray(i, 1) = resultArray(2, i)
Next i

Me.lbox_ID.List = IDArray
Me.lbox_Word.List = wordArray

End If

On Error GoTo 0

End Sub

' ----------------------------------------------------------------
Sub addItemByClick()
Call addWord
Me.Hide
End Sub

' ----------------------------------------------------------------
Sub addWord()

Dim selectedValue As String, selectedIndex As Long
Dim cell As Range
selectedValue = ""

Set cell = ActiveCell

If Me.lbox_ID.ListIndex > -1 Then
selectedIndex = Me.lbox_ID.ListIndex
selectedValue = Me.lbox_ID.List(selectedIndex)

cell.Value = "'" & selectedValue

End If

End Sub


--------------------------------------------------------------------





I get this whole code from a open source website and I tried to
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Forum statistics

Threads
1,223,897
Messages
6,175,271
Members
452,628
Latest member
dd2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top