ActiveX TextBox_Change with ActiveX ListBox_Click then clear TextBox causes recursive behavior

mchac

Well-known Member
Joined
Apr 15, 2013
Messages
531
I have an ActiveX TextBox with TextBox_Click code behind it such that each character I type triggers another sub to execute which then updates a table by updating a named cell that as a formula in it which drives the table. Then I have a ListBox that has ListFillRange linked to that table. The result is each character I type in the TextBox causes the ListBox to update. This is working fine.

The next thing I put in place was ListBox_Click code so that when I click on an item in the ListBox it updates a Label.Caption then sets ListBox.Value="". This is also working fine.

What I would like to now is have the TextBox clear after the Label.Caption is assigned. The problem is the TextBox clear causes the ListBox to update and the Label then gets the wrong value. This seems odd because the command assign the caption occurs before setting the TextBox = "" which resets the ListBox. But it doesnt seem to matter that the caption assignment occurrs first. The ListBox seems still selected so the update of the TextBox updates the ListBox so the Label gets the wrong value.

Any thoughts are greatly appreciated.

Code:
Private Sub TextBox5_Change()
    
    Call UpdateValues(TextBox5.Value)


    
End Sub

Code:
Sub UpdateValues(SearchString As String)
    Range("mySearchString").Value = SearchString
    Range("myStartPosition").Value = Range("myOverwriteProtection").Value
End Sub

Code:
Private Sub ListBox1_Click()
    
    ActiveSheet.OLEObjects("Label33").Object.Caption = ActiveSheet.OLEObjects("ListBox1").Object.Value
    
    ActiveSheet.OLEObjects("ListBox1").Object.Value = ""
    
    'ActiveSheet.OLEObjects("TextBox5").Object.Text = ""
    
End Sub



I'm new to ActiveX and I can't figure out or find a workaround.

Thanks in advance for any ideas.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Forum statistics

Threads
1,214,915
Messages
6,122,214
Members
449,074
Latest member
cancansova

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