command button disable userform

maxx_daddy

Board Regular
Joined
Dec 3, 2010
Messages
74
Hi,
I am a novice and any help would be appreciated (ive been working on this for 2 days)
I have a book that is going to be used to track sales. Currently It works awesome and I have a simple userform that has 4 text boxes and 2 combo boxes.
Also it has 3 command buttons (one to save the data and clear the boxes, and one to save the data and close excel and a cancel button)

I need help construting the "if-and-then" statement to lock the two "save" command buttons. I've tried a ton of things off the threads and I'm either putting it in the wrong place in VBA or I'm just not seeing the method properly. (plus I don't see how I could record this as a macro)
 

maxx_daddy

Board Regular
Joined
Dec 3, 2010
Messages
74
textbox 2 just needs input of anysort (customer name)
textbox 3 is programmed to take 4 characters
textbox 4 is programmed to take 5 characters (in the properties)
combobox 1 and 2 are both set by data validation to their source cells
textbox 5 just needs input
textbox 6 is optional no parameters are needed its just for comments if needed

i want the command buttons to be turned off until there is the appropriate data in each field (except tb6)
i'm was thinking that i need to put it in the text box_change for each tb but that hasnt been working for me. Also tried sheet change this book change? Just over my head for now.
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,651
The syntax would be

Code:
commandbutton2.Enabled = textbox2.Text <> "" And textbox3.Text <> "" And textbox4.Text <> "" And textbox5.Text <> "" And combobox1.Value <> "" And combobox2.Value <> ""
Where you place this depends on the structure of your code.
 

maxx_daddy

Board Regular
Joined
Dec 3, 2010
Messages
74
Well that sure was the head slap ah ha moment for me.
VOG thank you very much. I had tried that code a bunch of times but your comment :
"Where you place this depends on the structure of your code"
got me thinking straight.
This is solved, I placed this code in each combo box or text box and wallah, problem solved.

Thanks again.

Maxx_daddy

Private Sub TextBox5_Change()
CommandButton2.Enabled = TextBox2.Text <> "" _
And TextBox3.Text <> "" And TextBox4.Text <> "" _
And TextBox5.Text <> "" And ComboBox1.Value <> "" _
And ComboBox2.Value <> ""
End Sub
 

Forum statistics

Threads
1,082,570
Messages
5,366,364
Members
400,886
Latest member
Fchel

Some videos you may like

This Week's Hot Topics

Top