incapacitate a button depending if has some written

  • Thread starter Thread starter Frank Dulk
  • Start date Start date
F

Frank Dulk

as I do to enable or to incapacitate a button depending if has some written
thing or not in a text box

Example:

if I type some thing in the text box, it enables the button and if me
delete, incapacitates the button.
 
in the KeyUp event of the textbox put

if <YourTextBox>.text = "" then
<YourButton>.enabled = false
else
<YourButton>.enabled = true
end if
 
In the text box's AfterUpdate event, put code like:

Me.cmdMyButton.Enabled = Len(Me.txtMyTextbox & vbNullString) = 0

Replace cmdMyButton and txtMyTextbox with the names of your controls.
 
On second thought, you may want parentheses in there to make it more
readable.

Me.cmdMyButton.Enabled = (Len(Me.txtMyTextbox & vbNullString) = 0)

If the length of the text in the textbox is 0, (Len(Me.txtMyTextbox &
vbNullString) = 0) evaluates to True, so the button is enabled. If the
length of the text in greater than 0, it evaluates to False, so the button
is not enabled.
 
Back
Top