1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| Sub SelectionTexte(txt As Access.TextBox)
txt.SelStart = 0
txt.SelLength = Len(txt.Text)
End Sub
' Teste si année est bissextile
Public Function IsLeapYear(ByVal lngYear As Long) As Boolean
IsLeapYear = ((lngYear Mod 4 = 0) And (lngYear Mod 100 = 0)) _
Or (lngYear Mod 400 = 0)
End Function
' Transforme 25092014 en 25/09/2014
Function TransformerEnDate(ByVal strDateDepart As String) As Date
Dim strJour As String
Dim strMois As String
Dim strAnnee As String
If Len(strDateDepart) = 8 Then
Exit Function
End If
' Extraire les 3 parties de la date
strJour = Left(strDateDepart, 2)
strMois = Mid(strDateDepart, 3, 2)
strAnnee = Right(strDateDepart, 5)
Select Case strMois
Case "01", "03", "05", "07", "08", "10", "12"
If strJour > "31" Then
Exit Function
End If
Case "04", "06", "09", "11"
If strJour > "30" Then
Exit Function
End If
Case "02"
If strJour > "29" Then
Exit Function
Else
If (strJour = "29") And (IsLeapYear(strAnnee) = False) Then
Exit Function
End If
End If
Case Else
Exit Function
End Select
TransformerEnDate = DateSerial(strAnnee, strMois, strJour)
End Function |
Partager