Data Types For Excel Import To Access Table

So i am importing data from Excel into an Access table, and this data is overwriting the data (refreshing it) and not appending to.  When I created the table i was careful to define the data types for all the fields to ensure data was brought into the table correctly.  My question is this:  Is there a way as I bring new data (to overwrite) the table that I do not need to go the the exercise of "redefining" each field's data type to ensure (again) data is brought in correctly.  It seems Access wants to determine the data type even though the table it is overwriting has data types defined.  How can I overcome this?  Thanks.  - Tom
LVL 7
tomfarrarAsked:
Who is Participating?
 
Dale FyeCommented:
I just prefer not to do the import for precisely the issue you raise.  There is no Import Specification for importing Excel files, so you cannot simply define the columns like you would with an Advanced Import using a CSV file.  For that reason, I prefer to link to the data in Excel, whether it is a worksheet or a range.

I generally perform some data validity tests to make sure I'm not creating orphaned records, or to normalize the data (inserting values into Lookup fields which are not already there), and then I run an UPSERT query to update and insert records. and depending on the situation, maybe a delete query to delete records from the table which are not in the linked Excel file.

This also lets me flag records which have data of the wrong data type, which would not pass the data import process.

Dale
0
 
Dale FyeCommented:
Generally, when I want to pull data from Excel into Access, I simply link to the Excel data, and then write a query that uses conversion functions to explicitly convert the columns coming from Excel into Access.  Something like:

SELECT cstr(Field1) as Field1
cdbl(Field2) as Field2
cdate(Field3) as Field3
FROM lnk_Excel

Then I use that as the source of the query the will either append or update data in my Access table.
0
 
NorieVBA ExpertCommented:
How are you importing from Excel to Access?

Are you importing directly to the table?
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
tomfarrarAuthor Commented:
I am importing the file directly into the table.
0
 
tomfarrarAuthor Commented:
Dale - That is a thought.  Sounds like there is no option for Access using the data types already defined for the table.
0
 
tomfarrarAuthor Commented:
It is disappointing to me that Access can't (apparently) stick with the data types once established for a table.  Seems like a flaw to me, but maybe there is more to it than I understand.  I was hoping to get other thoughts on options that I had not considered when I submitted the question.  For example, if I were to link the data rather than import it, how would the data types be determined?  Would a formatted text field in an Excel spreadsheet be considered "text" in Access?  How about if the data file was a text file?  How would the data types be considered.

Bottom line I had hoped to get more discussion as I would guess this is a common problem.  Thanks .  - Tom
0
 
Dale FyeCommented:
When linking or importing from an Excel file, Access uses the first 25 (I think) rows to determine what it thinks the datatype of the column should be; sometimes this assessment is wrong.

With text files (delimited via comma, tab, or some other character), you can define an import specification, which tells Access how to treat each column, allowing you to specify the data type of each column, which gives you much greater control of the data import.

Unfortunately, MS has not made it a priority to allow users to create import specifications to use with Excel files.

Dale
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.