• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3964
  • Last Modified:

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!
0
emcullen
Asked:
emcullen
  • 2
1 Solution
 
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

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now