APAGANDO CAMPO LOGO APOS A INFORMACAO ERRADA

USUARIO.EXCLUIDOS 06/06/2007 11:21:50
#220000
Esse codigo abaixo ele verifica se a data e valida atras de um funcao e tambem nao deixa o usuario proceguir se o campo for branco.


Gostaria de complementar assim.

A cada tentativa de data invalida ,ele automaticamente ja apague o campo. Isso facilita sem a necessidade de um limpa tela toda vez que a data foi informada errada



Private Sub tb_dt_LostFocus()
' Se o tamanho do campo for igual a 0 ,ele retorna ate o preenchimento correto
If Len(tb_dt.ClipText) = 0 Then
MsgBox "Informe a data.", vbExclamation
tb_dt.SetFocus
Exit Sub
End If
If tb_dt.ClipText <> "" Then
' Se o valor digitado for diferente de branco ele entra na funcao FU_Checa
If Not Fu_Checa_Data(CStr(tb_dt.Text)) Then
MsgBox "DATA INVALIDA", vbExclamation, "ATENÇÃO"
tb_dt.SetFocus
Exit Sub
End If
End If
End Sub

LUIS.FLAVIO 06/06/2007 11:28:21
#220003
Verifique se isso dá.

Private Sub tb_dt_LostFocus()
' Se o tamanho do campo for igual a 0 ,ele retorna ate o preenchimento correto
If Len(tb_dt.ClipText) = 0 Then
MsgBox "Informe a data.", vbExclamation
tb_dt.SetFocus
Exit Sub
End If
If tb_dt.ClipText <> "" Then
' Se o valor digitado for diferente de branco ele entra na funcao FU_Checa
If Not Fu_Checa_Data(CStr(tb_dt.Text)) Then
MsgBox "DATA INVALIDA", vbExclamation, "ATENÇÃO"
tb_dt.text= Empty
tb_dt.SetFocus
Exit Sub
End If
End If
End Sub

USUARIO.EXCLUIDOS 06/06/2007 11:39:33
#220006
Resposta escolhida
as vezes da um erro no empty tenta colocar nada

  Private Sub tb_dt_LostFocus()
' Se o tamanho do campo for igual a 0 ,ele retorna ate o preenchimento correto
If Len(tb_dt.ClipText) = 0 Then
MsgBox "Informe a data.", vbExclamation
tb_dt.SetFocus
Exit Sub
End If
If tb_dt.ClipText <> "" Then
' Se o valor digitado for diferente de branco ele entra na funcao FU_Checa
If Not Fu_Checa_Data(CStr(tb_dt.Text)) Then
MsgBox "DATA INVALIDA", vbExclamation, "ATENÇÃO"
tb_dt.text= ""
tb_dt.SetFocus
Exit Sub
End If
End If
End Sub



USUARIO.EXCLUIDOS 06/06/2007 13:59:03
#220032
Eu dei uma melhorada no codigo.

Reparem que na linha em negrito tive que alterar para text __/__/____

Private Sub tb_dt_LostFocus()
' Se o tamanho do campo for igual a 0 ,ele retorna ate o preenchimento correto
If Len(tb_dt.ClipText) < 8 And Len(tb_dt.ClipText) = 0 Then
MsgBox "Informe a data.", vbExclamation, "ATENÇÃO"
tb_dt.SetFocus
Exit Sub
End If
If tb_dt.ClipText <> "" Then
' Se o valor digitado for diferente de branco ele entra na funcao FU_Checa
If Not Fu_Checa_Data(CStr(tb_dt.Text)) Then
MsgBox "DATA INVALIDA", vbExclamation, "ATENÇÃO"
'Limpa campo apos o retorno do foco
tb_dt.Text = "__/__/____"

tb_dt.SetFocus
Exit Sub
End If
End If
End Sub

Tópico encerrado , respostas não são mais permitidas