Changing field type to 'date/time' using code

N

Naz Virani

I am importing .csv files into Access. The files contain
date fields that Access recognizes as date fields, but
fails to convert them successfully. When the fields are
imported as 'text', no errors are generated; however, I
have to set the field type to date/time in Access after
import, which I am doing manually.

Is there a code that I can use to change the text field
type to date/time? There are several files being imported
and I would like to automate this process.

Thanks
 
D

Douglas J. Steele

The easiest approach is to mimic what Access does behind the scenes when you
make the change through the GUI:

1) Add a new Date field
2) Run an Update query to transfer the values to that new Date field
3) Delete the old Text field.
 
N

Naz Virani

Thanks for the reply. I discovered that the Alter Table
Alter Column statement accomplishes this.
 

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