Change Access field type from number to text in VBA.

I have imported an excel file into access.  One field is being read as numeric if the user entered only numbers into that column, but in fact in the Access application it is a text field.  When I try to join the imported table field (imported as "number") to the related field ("Text") it of course does not work.  How can I programatically change the field type from number to text after I import the table and before I need to join it to related tables?  Thank you!
emcullenAsked:
Who is Participating?
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
One of the problems with Excel data imports is that Access has to *ASSUME* the data type of a column based on the first value in that column.  
If it's numeric, then it assumes the column is numeric.

>How can I programatically change the field type from number to text after I import the table
CStr(YourNumberColumn) will return each value as text.

0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Another thought here.. most established developers will import Excel data into Access into a 'temporary' table with all text fields.  (I usually prefix these with timp_)
That way, all data makes it into Access without any data conversion errors.

Then, you can run a bunch of SELECT / UPDATE queries to 'scrub' your data, making sure dates are dates, numbers are numbers, etc.
Then when you're satisfied your data is good, INSERT into your ultimate destination table(s), then delete all from the temp table.

Hope this helps.
-Jim
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.