Change Procedure

E

ernie

lets assume i have inserted a form into my excel workbook
i put in a frame, one textbox, one combobox and one commandbutton. I want
the commandbutton to remain greyed out, so i put the property for enabled to
false. i need to have the enabled property to change back to true when all
the required information has been entered. so i have the codes like this:

Private Sub textbox_Change()
if textbox = "" or combobox = "" then
msgbox ("missing info")
else
commandbutton.enabled = true
end if
End Sub.

Private Sub combobox_Change()
if textbox = "" or combobox = "" then
msgbox ("missing info")
else
commandbutton.enabled = true
end if
End Sub

if i dont write a procedure for both control then when i do any changes on
the control that doesnt have a change procedure, the commandbutton remains
unchange. Is there another way to do this. i want to eliminate writing so
many sub procedures.
 
B

Bill Pfister

Ernie, write one procedure that checks all your controls and call that
procedure from each event.


private sub ValidateControls()
if ((textbox = "") or (combobox = "")) then
msgbox ("missing info")
commandbutton.enabled = false ' reset if something is deleted
else
commandbutton.enabled = true
end if
End sub


Private Sub combobox_Change()
ValidateControls
end sub

Private Sub textbox_Change()
ValidateControls
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