Function ImportDate (anydate As Variant) As Variant
'
' This routine converts a field in any of the following formats
' to a date:
'
'   MMDDYY
'   YYMMDD
'   MM/DD/YY
'   YY/MM/DD
'   MM/DD/CCYY
'   CCYY/MM/DD
'
' The logic of determining what type the date is is based upon
' a "/" in the 3rd position and whether the 1st two characters
' fall between "01" and "12".  Although this logic should work
' for dates in this century, the next century will be a problem
' because the year could be between "01" and "12" which is the
' same as the month.
'
    Dim MM As String

    If IsNull(anydate) Then
        Exit Function
    End If
    
    MM = Left(anydate, 2)
    If Len(anydate) = 6 Then
'
' Date is 6 characters in length so it must be either MMDDYY or
' YYMMDD
'
        If anydate = "000000" Or anydate = "     0" Then
            ImportDate = Null
        Else
'
' Check to see if date is MMDDYY
'
            If MM >= "00" And MM <= "12" Then
                ImportDate = MM & "/" & Mid(anydate, 3, 2) & "/" & Right(anydate, 2)
            Else
'
' Date must be formatted YYMMDD
'
                ImportDate = Mid(anydate, 3, 2) & "/" & Right(anydate, 2) & "/" & Left(anydate, 2)
            End If
        End If
    End If
'
' Check to see if date is 8 characters in length
'
    If Len(anydate) = 8 Then
'
' Date is 8 characters in length so it must be one of the following:
'
'   MM/DD/YY
'   YY/MM/DD
'   YYYYMMDD
'   MMDDYYYY
'
        If anydate = "00000000" Or anydate = "00/00/00" Then
            ImportDate = Null
        Else
            If Mid(anydate, 3, 1) = "/" Then
'
' Date has a "/" embedded in the 3rd position
'
                If MM >= "00" And MM <= "12" Then
                    ImportDate = anydate
                Else
                    ImportDate = Right(anydate, 5) & "/" & Left(anydate, 2)
                End If
            Else
'
' If 1st 2 positions are between 01 & 12 assume format to be MMDDYYYY
'
                If MM >= "01" And MM <= "12" Then
                    ImportDate = MM & "/" & Mid(anydate, 3, 2) & "/" & Right(anydate, 4)
                Else
'
' Otherwise date must be CCYYMMDD
                    ImportDate = Mid(anydate, 5, 2) & "/" & Right(anydate, 2) & "/" & Left(anydate, 4)
                End If
            End If
        End If
    End If
'
' Check to see if date is 10 characters in length
'
    If Len(anydate) = 10 Then
'
' Date is 10 characters in length so it must be one of the following:
'
'   MM/DD/CCYY
'   CCYY/MM/DD
'
        If anydate = "0000000000" Or anydate = "00/00/0000" Or anydate = "0000/00/00" Then
            ImportDate = Null
        Else
'
' If 1st 2 postions are between 01 & 12 assume format to be MM/DD/CCYY
'
            If MM >= "01" And MM <= "12" Then
                ImportDate = anydate
            Else
                ImportDate = Mid(anydate, 6, 5) & "/" & Left(anydate, 4)
            End If
        End If
    End If

End Function
