Validade Text Box - RESOLVIDO

jovemlima

05-11-2014 13:47:57

Bom dia a todos.
Gostaria de validar critérios de preenchimento de TextBox. Como um campo deve ter o formato de XXX-XX.XXXX e outro de número e se não for assim não passar para o próximo, podendo ou não dar algum mensagem. Tentei usar um evento mas não tive êxito. Gostaria de uma ajuda.
quando uso este evento " Private Sub txtProcedimento_Validate(Cancel As Boolean)" automaticamente ele cria este " Private Sub txtProcedimento_Change()" e não funciona, poderiam me mostrar como faze-lo?
Private Sub txtProcedimento_Validate(Cancel As Boolean)
IsNumeric (txtProcedimento.Text)
Cancel = True
ElseIf txtProcedimento.Text < 21 Then
MsgBox "Digite uma idade superior a 21"
Cancel = True
Cancel = False
End If
End Sub

jovemlima

26-01-2015 15:25:36

Achei aqui o que precisava, Valeu.
Private Sub txtCompetencia_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)

If Not IsDate(txtCompetencia) Then
MsgBox "Verifique a data>"
MsgBox "Obs.: Para cancelar preencha o campo e tecle Cancelar"
txtCompetencia = ""
Cancel = True
End If
End Sub

Private Sub txtCompetencia_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
txtCompetencia.MaxLength = 5
If KeyAscii < Asc("0") Or KeyAscii > Asc("9") Then
MsgBox ("Somente números"), vbCritical, "Atenção"
KeyAscii = 0
End If

If Len(txtCompetencia) = 2 Then
txtCompetencia.Text = txtCompetencia.Text & "/"
SendKeys "{End}", False
End If

End Sub

SDS
Luiz