Ver Mensaje Individual
  #5 (permalink)  
Antiguo 02-05-2008, 20:52:09
Avatar de J.M.Movilla
J.M.Movilla J.M.Movilla is offline
Administrator
 
Registrado: dic 2002
Ubicación: BURGOS - ESPAÑA
Posts: 5.431
J.M.Movilla Valoración +2
Predeterminado Re: Validaciones de fechas?

También puedes montar una función para validar las fechas. La pones en un Módulo, tal que así:
Código:
Function ValeFecha(FecTxt As String) As Date
    Dim cDia As String
    
    On Local Error Resume Next
    If FecTxt <> "" Then
        cDia = Left(FecTxt, 2)
        While InStr(FecTxt, "-") > 0
            n = InStr(FecTxt, "-")
            FecTxt = Left(FecTxt, n - 1) & Mid(FecTxt, n + 1)
        Wend
        If Mid(FecTxt, 3, 1) <> "/" Then FecTxt = Left(FecTxt, 2) & "/" & Mid(FecTxt, 3)
        If Mid(FecTxt, 6, 1) <> "/" Then FecTxt = Left(FecTxt, 5) & "/" & Mid(FecTxt, 6)
        FecTxt = Left(FecTxt, 10)
        FecTxt = Format(FecTxt, "dd/mm/yyyy")
        Err = 0
        FecTxt = CDate(FecTxt)
        If Left(FecTxt, 2) <> cDia Or Err <> 0 Then
            x = MsgBox("¡¡¡ A T E N C I O N !!!" & Chr(10) & _
                Chr(10) & _
                "Compruebe el formato de esta fecha.", vbCritical)
            FecTxt = Null
        End If
    End If
    ValeFecha = FecTxt
End Function
Con esto puedes introducir una fecha poniendo simplemente "020508" y la función te devolverá "02/05/2008". Y si pones "31-02-2008" te dirá que "Compruebes el formato..."
Sólo tienes que poner en el evento "_LostFocus" del textbox las líneas
Código:
textbox1 = ValeFecha(textbox1)
if isnull(textbox1) then textbox1.SetFocus
__________________
José María Movilla Cuadrado
______________________

Visual Basic Videos Programacion Foro Programacion
Tutoriales Programacion Trucos Programacion Codigos Programacion
Responder Con Cita