Franz:
You can automate the process after importing the data from the tab delimited
file by first creating the following procedure in a standard module in the
database:
Public Sub CreateDateColumn(strImportedTable As String, _
strImportedDateColumn As String, _
strNewDateColumn As String)
Const FIELDEXISTS = 3191
Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Dim strSQL As String
' add new column of date/time data type
' if doesn't already exist
Set dbs = CurrentDb
Set tdf = dbs.TableDefs(strImportedTable)
With tdf
Set fld = .CreateField(strNewDateColumn, dbDate)
On Error Resume Next
.Fields.Append fld
Select Case Err.Number
Case 0
' no error
Case FIELDEXISTS
' do nothing
Case Else
' unknown error
MsgBox Err.Description, vbExclamation, "Error"
End Select
On Error GoTo 0
End With
'populate new date column
strSQL = "UPDATE " & strImportedTable & _
" SET " & strNewDateColumn & _
" = DATESERIAL(" & _
" RIGHT(" & strImportedDateColumn & ",4)," & _
" MID(" & strImportedDateColumn & ",3,2)," & _
" LEFT(" & strImportedDateColumn & ",2))" & _
" WHERE LEN(TRIM(NZ(" & strImportedDateColumn & _
" ,""""))) > 0 AND " & strNewDateColumn & _
" IS NULL"
dbs.Execute strSQL, dbFailOnError
End Sub
This will create new column of date/time data type if it doesn't already
exist and then fill it with dates computed from the text values in the
original imported column. Any imported rows without dates will be ignored,
and any rows where the new date/time values have already been entered will
be ignored. Call the procedure by passing the name of the table, the
imported column and the name you want to call the new column into it like so:
CreateDateColumn "ImportedTable","ImportedDateColumn","NewDateColumn"
Make sure the table is not open when the function is called.
Having filled the new column use that in forms, reports, queries etc. The
original imported text column can be left in place, but ignored.
Ken Sheridan
Stafford, England