[AccessD] CheckDate?

S D accessd667 at yahoo.com
Tue Nov 2 04:15:16 CST 2004


Hi group,
 
I created a routine that checks if a date is correct. Can anybody review this one? I think that it's unnecessary complex.
 
TIA
 
Sander
If Not IsNull(txtExportDate) Then
        'Check month part
        If Mid(txtExportDate, 4, 2) > 12 Then
            'incorrect date!
        Else
            blnDate = True
        End If
        'Check day part
        Select Case Left(txtExportDate, 2)
        Case 31
            If (Mid(txtExportDate, 4, 2) = 1) Or _
            (Mid(txtExportDate, 4, 2) = 3) Or _
            (Mid(txtExportDate, 4, 2) = 5) Or _
            (Mid(txtExportDate, 4, 2) = 7) Or _
            (Mid(txtExportDate, 4, 2) = 8) Or _
            (Mid(txtExportDate, 4, 2) = 10) Or _
            (Mid(txtExportDate, 4, 2) = 12) Then
                'correct day - month combi
                blnDate = True
            Else
                'incorrect day-month combi
                blnDate = False
            End If
        Case 30
            If (Mid(txtExportDate, 4, 2) = 4) Or _
            (Mid(txtExportDate, 4, 2) = 6) Or _
            (Mid(txtExportDate, 4, 2) = 9) Or _
            (Mid(txtExportDate, 4, 2) = 11) Then
                'correct day - month combi
                blnDate = True
            Else
                'incorrect day-month combi
                blnDate = False
            End If
        Case 28
            'Check if month is february
            If Mid(txtExportDate, 4, 2) = 2 Then
                'correct date
                blnDate = True
            Else
                'incorrectdate
                blnDate = False
            End If
        Case 1 To 27
            'correct day - month combi
            blnDate = True
        Case 29
            'Check if month is february
            If Mid(txtExportDate, 4, 2) = 2 Then
                'incorrect date
                blnDate = False
            Else
                'correctdate
                blnDate = True
            End If
        Case Else
            blnDate = False
        End Select
    Else
        'Null date
        Call MsgBox("U heeft geen exporteer datum opgegeven! Deze is verplicht.", _
                     vbExclamation, "Onjuiste datum")
        txtExportDate.SetFocus
        Exit Sub
    End If
    If Not blnDate Then
        Call MsgBox("De datum die u heeft opgegeven is onjuist! " _
             & vbCrLf & "Vul een datum in met formaat: DD-MM-YYYY" _
             & vbCrLf & "" _
             , vbCritical, "Onjuiste datum")
        txtExportDate.SetFocus
        Exit Sub
    Else
 

			
---------------------------------
Do you Yahoo!?
 Check out the new Yahoo! Front Page.  www.yahoo.com/a


More information about the AccessD mailing list