I have this code below in the textbox Change event. It is part of an Auto-Complete code.
It all works ok, except when I try to change the textbox string to all three columns of the listview. This makes the Change event fire again and I get the error:
Object variable or With block variable not set
on this line:
vb Code:
lvwMembers.FindItem(txtSearch.Text, , , lvwPartial).Selected = True
My complete code is:
vb Code:
Private Sub txtSearch_Change() On Error GoTo ErrTrap Dim LvwItm As ListItem Dim Strt As Integer 'If firing in response to a backspace or delete, don't run the auto-complete 'complete code. (Otherwise you wouldn't be able to back up.) If blnBackSpace = True Or txtSearch.Text = vbNullString Then blnBackSpace = False Exit Sub End If 'Run through the available items and grab the first matching one. If lvwMembers.ListItems(lvwMembers.SelectedItem.index).EnsureVisible = True Then 'search the first column (First Name) lvwMembers.FindItem(txtSearch.Text, , , lvwPartial).Selected = True End If 'If something was chosen then we get the rest of it Strt = Len(txtSearch.Text) 'add full name to txtSearch If Len(lvwMembers.SelectedItem.SubItems(1)) = 0 Then txtSearch.Text = lvwMembers.SelectedItem.Text & " " & lvwMembers.SelectedItem.SubItems(2) Else txtSearch.Text = lvwMembers.SelectedItem.Text & " " & lvwMembers.SelectedItem.SubItems(1) _ & " " & lvwMembers.SelectedItem.SubItems(2) End If txtSearch.SelStart = Strt txtSearch.SelLength = Len(txtSearch.Text) - Strt Exit Sub




Reply With Quote