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
'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
Private Sub txtDATA_VALIDACAO_LostFocus()
Select Case TestaData(txtDATA_VALIDACAO)
'Valida ANO
Case Is = "ANO"
MsgBox "OBS: Data Inválida!", vbCritical
txtDATA_VALIDACAO = ""
Exit Sub
'Valida MES
Case Is = "MES"
MsgBox "OBS: Data Inválida!", vbCritical
txtDATA_VALIDACAO = ""
Exit Sub
'Valida DIA
Case Is = "DIA"
MsgBox "OBS: Data Inválida!", vbCritical
txtDATA_VALIDACAO = ""
Exit Sub
End Select
txtDATA_PREV_FAT.Text = Format(DateAdd("d", "15", txtDATA_VALIDACAO), "dd/mm/yyyy")
txtDATA_VENC_NF.Enabled = True
txtDATA_VALIDACAO.Enabled = False
End Sub