Gruporsf:
Segue abaixo o Código para o campo data:
Ele preenche com as "/", no formato 99/99/9999 e verifica se a data informada é valida!
'Função p/ validar a Data
Public Function TestaData(VerData As String)
Dim xUltimoDiaMes As String
Dim xyAno As Integer
Dim xyMes As Integer
'Testa o Ano
If Mid(VerData, 7, 4) < 1980 Or Mid(VerData, 7, 4) > 2010 Then
TestaData = "ANO" 'False
Exit Function
Else
xyAno = Mid(VerData, 7, 4)
End If
'Testa o Mes
If Mid(VerData, 4, 2) < 1 Or Mid(VerData, 4, 2) > 12 Then
TestaData = "MES" 'False
Exit Function
Else
xyMes = Mid(VerData, 4, 2)
End If
'verifica o ultimo dia do mes da data solicitada
xUltimoDiaMes = Day(DateSerial(xyAno, xyMes + 1, 1) - 1)
'testa o DIA
If Mid(VerData, 1, 2) < 1 Or Mid(VerData, 1, 2) > xUltimoDiaMes Then
TestaData = "DIA" 'False
Exit Function
Else
TestaData = True
End If
End Function
***************************************************************
Function CampoData(OBJ As Object, Keyasc As Integer)
If Not ((Keyasc >= Asc("0") And _
Keyasc <= Asc("9")) Or Keyasc = 8) Then
Keyasc = 0
Exit Function
End If
If Keyasc <> 8 Then
If Len(OBJ.Text) = 2 Or _
Len(OBJ.Text) = 5 Then
OBJ.Text = OBJ.Text + "/"
OBJ.SelStart = Len(OBJ.Text)
End If
End If
End Function
***************************************************************
Private Sub txtDATA_Change()
txtDATA.MaxLength = 10
End Sub
***************************************************************
Private Sub txtDATA_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys "{TAB}"
KeyAscii = 0
End If
'Formata automaticamente a entrada de data
CampoData txtDATA, KeyAscii
End Sub
***************************************************************
Private Sub txtDATA_LostFocus()
Select Case TestaData(txtDATA)
Case Is = "ANO"
frmValida.Show
frmNotas.Visible = False
Exit Sub
Case Is = "MES"
frmValida.Show
frmNotas.Visible = False
Exit Sub
Case Is = "DIA"
frmValida.Show
frmNotas.Visible = False
Exit Sub
End Select
End Sub