Show Results in TextBoxes, ONLY if All TextBoxes have Data in them

R

RyanH

I have a total of 8 Textboxes and 1 ComboBox in a UserForm. Textboxes 1-4
show calculation results that are dependent on Textboxes 5-8 and the
ComboBox. I am currently using the Change Event in Textboxes 5-8 and the
ComboBox for an instant calculation for the user to see. My question is how
do I get Textboxes 1-4 to be blank if any of the Textboxes 5-8 or the
Combobox is blank.
 
J

John Bundy

Try something like this
Function checkBoxes(w, x, y, z)
Dim tbEmpty As Boolean
tbEmpty = False
If w = "" Then tbEmpty = True
If x = "" Then tbEmpty = True
If y = "" Then tbEmpty = True
If z = "" Then tbEmpty = True
If tbEmpty = True Then checkBoxes = "True" Else checkBoxes = "False"
End Function


Private Sub CommandButton1_Click()
Dim txt1, txt2, txt3, txt4 As String
txt1 = Trim(TextBox5.Text)
txt2 = Trim(TextBox6.Text)
txt3 = Trim(TextBox7.Text)
txt4 = Trim(TextBox8.Text)

If checkBoxes(txt1, txt2, txt3, txt4) = "True" Then Exit Sub
'calculations

End Sub
 
R

RyanH

I appreciate the fast response John! I'm not sure if this is what I need. I
think your example requires CheckBoxes and/or a Command Button Click Event.
I need the Values of TextBoxes 1-4 to be "" if all the TextBoxes 5-8 and the
ComboBox are blank.
 
J

John Bundy

I just named it checkboxes, as in check the textboxes. I did forget the
combobox. This should cover you, but I did leave it as a button click event,
put the function outside of course but put the code inside the button click
event inside whatever event you are using.

Function checkBoxes(v, w, x, y, z)
Dim tbEmpty As Boolean
tbEmpty = False
If w = "" Then tbEmpty = True
If x = "" Then tbEmpty = True
If y = "" Then tbEmpty = True
If z = "" Then tbEmpty = True
If tbEmpty = True Then checkBoxes = "True" Else checkBoxes = "False"
End Function


Private Sub CommandButton1_Click()
Dim txt1, txt2, txt3, txt4, cmb1 As String
txt1 = Trim(TextBox5.Text)
txt2 = Trim(TextBox6.Text)
txt3 = Trim(TextBox7.Text)
txt4 = Trim(TextBox8.Text)
cmb1 = Trim(ComboBox1.Text)

If checkBoxes(cmb1, txt1, txt2, txt3, txt4) = "True" Then
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top