Fazer verificao em textbox

Edu

05-05-2011 12:06:43

Tenho um formulario no excel, nesse formulario eu tenho dua textbox e um commandbutton.
Gostaria de saber se tem como fazer uma verificaçao do tipo, se o valor do textbox 1 e o valor do textbox 2 forem diferente de vazio, entao somente assim habilitar o botao.
eu ja tentei com o seguinte codigo:

Private sub liberar_botao()
if textbox1.value <> "" and textbox2.value<>"" then
commandbutton1.enabled = true
else
commandbutton1.enabled = false
end if
end sub


porem com esse codigo nao funciona.
se alguem souber como fazer ficarei grato

joseA

05-05-2011 12:40:55

Penso que o ideal seria utilizar o evento exit dos TextBox's, tipo:

Código: Selecionar todos

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If TextBox1.Value <> "" And TextBox2.Value <> "" Then
CommandButton1.Enabled = True
Else
CommandButton1.Enabled = False
End If
End Sub
Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If TextBox1.Value <> "" And TextBox2.Value <> "" Then
CommandButton1.Enabled = True
Else
CommandButton1.Enabled = False
End If
End Sub