lundi 4 janvier 2021

Checking if some textbox is empty and then running event in VBA

I am going to make a simple userform for finding value and display results in ListBox. I have a 15 textboxes and one button for finding. Source of data for finding is always the same. Only input value (for finding) will dynamic. My conception is:

  1. Declarate one public variable and this will be input value
  2. checking if some textbox is empty
  3. If not, declarate variable will TextBox.Value (which is not empty) and execute finding method

What is the problem? Generally, I can write a lot of codes for all textboxes For example:

  If TextBox1.Value <> "" Then 
    ' execute finding method - input is TextBox1.Value
    ElseIf TextBox2.Value <> "" Then 
    ' execute finding method - input is TextBox2.Value
   ...

And generate 15x ElseIf or secound option create separately button. It will looks funny 15 buttons.

But a both solution are not perfect. How can I implement good solution for this?

Aucun commentaire:

Enregistrer un commentaire