[AccessD] CheckDate?

Heenan, Lambert Lambert.Heenan at AIG.com
Thu Nov 11 08:23:06 CST 2004


I'm one of those odd people who always use a calendar form (not the MS
Active-X control) for date entering, but if you really must allow those
whacko users to type a date in a box then what's wrong with this code...

Dim bIsValideDate As Boolean
	bIsValideDate =isDate(txtYourFormControl)
	If bIsValideDate  Then
		...
	Else
		MsgBox "Can you at least type a valid date in the box!
	End If

Is that sufficiently uncomplex :-)

"isDate()" is a built in function.

Lambert

> -----Original Message-----
> From:	accessd-bounces at databaseadvisors.com
> [SMTP:accessd-bounces at databaseadvisors.com] On Behalf Of Joe Hecht
> Sent:	Wednesday, November 10, 2004 10:11 PM
> To:	'Access Developers discussion and problem solving'
> Subject:	RE: [AccessD] CheckDate?
> 
> I used to know someone who would only use a calendar control for date
> input
> to insure proper date.
> 
> JOE HECHT
> LOS ANGELES CA 
>  jmhla at earthlink.net
> 
> -----Original Message-----
> From: accessd-bounces at databaseadvisors.com
> [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of S D
> Sent: Tuesday, November 02, 2004 2:15 AM
> To: accessd at databaseadvisors.com
> Subject: [AccessD] CheckDate?
> 
> 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
> -- 
> _______________________________________________
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
> 
> 
> -- 
> _______________________________________________
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com



More information about the AccessD mailing list