Import CSV file into Access
-
- 5StarLounger
- Posts: 627
- Joined: 03 Feb 2010, 15:02
Import CSV file into Access
I have a CSV file that I would like to import into Access. Some of the fields are numbers but they are really text. When I import them, the leading 0s are truncated. Is there a way to prevent this?
-
- 4StarLounger
- Posts: 482
- Joined: 24 Jan 2010, 15:02
- Location: Colorado, USA
Re: Import CSV file into Access
The quickest way is to append it to an existing table where the data is defined as text rather than numeric. When you do the import external data, that is one of the options you have.
Wendell
You can't see the view if you don't climb the mountain!
You can't see the view if you don't climb the mountain!
-
- 5StarLounger
- Posts: 627
- Joined: 03 Feb 2010, 15:02
Re: Import CSV file into Access
There is an existing table in the database that was imported from an Excel file. Can I copy this database without the data and append to this empty table?
-
- 4StarLounger
- Posts: 482
- Joined: 24 Jan 2010, 15:02
- Location: Colorado, USA
Re: Import CSV file into Access
You could do that, or you could create a new table that has the correct data types set for the various fields and import it into that. We often do that where we have to import data on a regular basis, and simply run a delete query against that table before we do the import.
Wendell
You can't see the view if you don't climb the mountain!
You can't see the view if you don't climb the mountain!
-
- 5StarLounger
- Posts: 627
- Joined: 03 Feb 2010, 15:02
Re: Import CSV file into Access
How would I structure a delete query to delete data from a table?
-
- 4StarLounger
- Posts: 482
- Joined: 24 Jan 2010, 15:02
- Location: Colorado, USA
Re: Import CSV file into Access
It's one of the basic action query types like Make Table, or Append, etc. In it's simplest form it looks likeThat SQL syntax will delete all the records in the specified table. It will warn you before it does unless you have warnings turned off. But it is very powerful and cannot be undone, so make sure it does what you want before you start using such a query. I usually create it as a SELECT query to start with and test it, and then change it to a DELETE.
Code: Select all
DELETE * FROM tblMyTable
Wendell
You can't see the view if you don't climb the mountain!
You can't see the view if you don't climb the mountain!
-
- 3StarLounger
- Posts: 390
- Joined: 26 Jan 2010, 16:02
- Location: Las Vegas, NV
Re: Import CSV file into Access
mathewR,
Here is another possibility, in addition to Wendell's solution.
If you use the Import Spreadsheet Wizard, there is a dropdown setting from which to choose the data type. If you choose Text, the imported data retains leading zeroes.
See attached screenshot of Import Spreadsheet Wizard. Also see screenshot (attached) of resulting table. Hope this helps.
Here is another possibility, in addition to Wendell's solution.
If you use the Import Spreadsheet Wizard, there is a dropdown setting from which to choose the data type. If you choose Text, the imported data retains leading zeroes.
See attached screenshot of Import Spreadsheet Wizard. Also see screenshot (attached) of resulting table. Hope this helps.
You do not have the required permissions to view the files attached to this post.
Carol W.
-
- 5StarLounger
- Posts: 627
- Joined: 03 Feb 2010, 15:02
Re: Import CSV file into Access
Thank you both for you help.