Date Validation and Date Precision

  • Thread starter Rajesh B. Patel
  • Start date
R

Rajesh B. Patel

Hi,

I have several Date/Time fields that I would like to validate slightly
differently than Access typically does. Basically I want to allow the
user to enter a year only into the date field in addition to all the
formats supported by Date/Time fields. I allow this with the following code:

Public Type DateInfo
strDate As String
blnIsApprox As Boolean
End Type

Public Static Function FormatDate(ToFormat As String) As DateInfo
If IsDate(ToFormat) Then
FormatDate.strDate = FormatDateTime(ToFormat)

' this is not quite right!!!
FormatDate.blnIsApprox = False
' use 100-9999 because that's what MS handles
' correctly with FormatDateTime function
ElseIf ToFormat >= 100 And ToFormat <= 9999 Then
FormatDate.strDate = FormatDateTime("1/1/" & ToFormat)
FormatDate.blnIsApprox = True
End If
End Function

As you can see in the above code I also want to determine whether the
user entered a imprecise (missing day and/or month) date into the
textbox. It is easy for me to detect missing day AND month since I
handle that in it's own elseif clause.

I cannot quite get it right in the other case. I want every table with a
date field to also have a boolean representing whether this date was
entered without one or more of the components of a full date (day,
month, or year).

I have gone through the date functions in VBA and it appears that
everything gets converted to a DateTime type before I can check for the
presence/absence of day or month. After it has been converted the
missing field is filled with a default (which looks like it's 1). Are
there are clean solutions to this problem short of writing a complete
date validation routine and reinventing the wheel? Thanks in advance to all.

raj
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top