472,992 Members | 3,803 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,992 software developers and data experts.

How can I import 2 csv files into 1 table

I will try to explain my situation. I know that it is hard to offers
solutions without fully understanding what people would like to
achieve.

I receive 2 csv files every month. The csv files change name each
month. Each file contains 13 columns and around 20k rows. In each file,
the first row is the heading.

I have created a database that helps me sort out the data. Prior to
importing into the database, I have been copying the csv data into one
xls file. I then run an Excel macro to format the data. The macro does
a few things. The first thing it does is remove any blank spaces in the
text of column A. Then the macro changes the format of column I to
number with no decimals and changes the format of column L to short
date. I then run an Access macro to import the xls file into a table
and do a number of other things before spitting out the 72 Excel files
I use for reporting. I have formatted the table to accept the data from
the xls file. For example, Column J contains notes, which exceeded the
default character length. The notes were truncated when I tried to
import the csv file straight to a table. Column I contains numbers and
text which were left blank when I tried to import the csv into a table.

I would like to incorporate the formatting and importation of these
files into the macro that I already use to sort and export 72 Excel
files. I would like to place the 2 csv files in a directory and have
Access import the files into a single table. Both csv files always
start with the same title (file_name ***.csv). The csv files should be
imported from a different directory than the target for the exported
xls files.

I am not a programmer. I have been stumbling through this process for
about a week now. The purpose for the database is to make my job
easier, but I have also been enjoying the challenge. Let me know if you
can help me out or if I can offer more clarification.

Thanks,
Mark

Jul 23 '06 #1
3 8742

ninrulz wrote:
I will try to explain my situation. I know that it is hard to offers
solutions without fully understanding what people would like to
achieve.

I receive 2 csv files every month. The csv files change name each
month. Each file contains 13 columns and around 20k rows. In each file,
the first row is the heading.
use TransferText
I would like to incorporate the formatting and importation of these
files into the macro that I already use to sort and export 72 Excel
files. I would like to place the 2 csv files in a directory and have
Access import the files into a single table. Both csv files always
start with the same title (file_name ***.csv). The csv files should be
imported from a different directory than the target for the exported
xls files.
You don't store formatted data in a database. That's for presentation.
Importing is in a different folder? So? use an import spec and maybe
specify the path for input and output in a table or something (so you
can modify/store it).

Jul 23 '06 #2
The script I am using is below. There are two additional issues I need
to overcome.

Function ImportFiles()
Dim strPath As String
Dim strFile As String
strPath = "C:\Source Files\"
strFile = Dir$(strPath & "*.csv")
Do While Len(strFile) 0
DoCmd.TransferText acImportDelim, , "Monthly Report -
unsorted", strPath & strFile, True
strFile = Dir$
Loop
End Function

1.) One of the fields gets a few truncation errors when I import. There
are over 400 characters in some of the cells of one column. I need to
do one of 2 things. A.) Increase the size or change the format of the
field to accommodate the data, or B.) Because I do not really care
about the truncated data, prevent the creation of the ImportErrors
Tables.

Error Field Row
Field Truncation Notes 8364
Field Truncation Notes 9617
Field Truncation Notes 12948
Field Truncation Notes 17610

2.) Remove the blank spaces from the first column of each csv file,
prior to importing it. The first row of each csv file is the heading
and the spaces need to be removed from that as well.

Example:
Heading Name Example changed to HeadingNameExample

I would like to automate the import of these csv files without having
to make any changes to them. Is there a way to makes these changes as
part of the script?

Thank you,
Mark

pi********@hotmail.com wrote:
ninrulz wrote:
I will try to explain my situation. I know that it is hard to offers
solutions without fully understanding what people would like to
achieve.

I receive 2 csv files every month. The csv files change name each
month. Each file contains 13 columns and around 20k rows. In each file,
the first row is the heading.

use TransferText
I would like to incorporate the formatting and importation of these
files into the macro that I already use to sort and export 72 Excel
files. I would like to place the 2 csv files in a directory and have
Access import the files into a single table. Both csv files always
start with the same title (file_name ***.csv). The csv files should be
imported from a different directory than the target for the exported
xls files.
You don't store formatted data in a database. That's for presentation.
Importing is in a different folder? So? use an import spec and maybe
specify the path for input and output in a table or something (so you
can modify/store it).
Jul 26 '06 #3
Mark

Maybe you should import into a buffer table first, then run one or more
queries to clean up the data, then another append query to finally put your
data into the real table. The field with a large amount of text could go
into a memo field and your append query could truncate the data if required
using something like the Left function.

You buffer table could have all fields as basic text so there are no rules
to worry about, nothing required. That way you file will always import. Then
worry about the validity of the data.

That would be my approach. In that way you can even run a validation routine
against the data before you commit it to your very valuable real data.

Jeff Pritchard
________________
Asken Research Pty. Ltd.
Access Database Developers
http://www.asken.com.au

"ninrulz" <ni********@hotmail.comwrote in message
news:11**********************@p79g2000cwp.googlegr oups.com...
The script I am using is below. There are two additional issues I need
to overcome.

Function ImportFiles()
Dim strPath As String
Dim strFile As String
strPath = "C:\Source Files\"
strFile = Dir$(strPath & "*.csv")
Do While Len(strFile) 0
DoCmd.TransferText acImportDelim, , "Monthly Report -
unsorted", strPath & strFile, True
strFile = Dir$
Loop
End Function

1.) One of the fields gets a few truncation errors when I import. There
are over 400 characters in some of the cells of one column. I need to
do one of 2 things. A.) Increase the size or change the format of the
field to accommodate the data, or B.) Because I do not really care
about the truncated data, prevent the creation of the ImportErrors
Tables.

Error Field Row
Field Truncation Notes 8364
Field Truncation Notes 9617
Field Truncation Notes 12948
Field Truncation Notes 17610

2.) Remove the blank spaces from the first column of each csv file,
prior to importing it. The first row of each csv file is the heading
and the spaces need to be removed from that as well.

Example:
Heading Name Example changed to HeadingNameExample

I would like to automate the import of these csv files without having
to make any changes to them. Is there a way to makes these changes as
part of the script?

Thank you,
Mark

pi********@hotmail.com wrote:
>ninrulz wrote:
I will try to explain my situation. I know that it is hard to offers
solutions without fully understanding what people would like to
achieve.

I receive 2 csv files every month. The csv files change name each
month. Each file contains 13 columns and around 20k rows. In each file,
the first row is the heading.

use TransferText
I would like to incorporate the formatting and importation of these
files into the macro that I already use to sort and export 72 Excel
files. I would like to place the 2 csv files in a directory and have
Access import the files into a single table. Both csv files always
start with the same title (file_name ***.csv). The csv files should be
imported from a different directory than the target for the exported
xls files.
You don't store formatted data in a database. That's for presentation.
Importing is in a different folder? So? use an import spec and maybe
specify the path for input and output in a table or something (so you
can modify/store it).

Jul 26 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: The Pig | last post by:
Guys, Got a bunch of DBF files all named pikcup.dbf. They are all stored under a directory named c:\reports but are all under multiple sub directories. I need Access to import all pickup.dbf...
1
by: Dan | last post by:
Could someone please help me with auto importing a series of data files into an Access table. I tried to follow code given below in a previous messagebut i'm getting error messages. Here's my...
4
by: khutch | last post by:
Not that up on MS Access. I understand that the TransferText command can be used to import csv files into a database. Question: Does the text file have to mirror the alignment of the table columns...
0
by: Chris via AccessMonster.com | last post by:
I have deployed an app in the app is a form that imports all files in a directory. Stores the files as tables with the tablename as the filename. Works great! I would like to take this one step...
3
by: deko | last post by:
I've been trying to use the Access Import Wizard to expedite importing data into my mdb. The nice thing about the wizard is that I can import from different file formats - txt, xls, even Outlook -...
2
by: KingoftheKings | last post by:
I'm new here. I want a help with VB codes that will import text or excel files from a specified directory in to an existing or new Access table. I have written some codes, but when I click the...
1
by: Jim Johnson | last post by:
I have an application that needs to import a DLL file for some database call like - #import "c:\Program Files\Common Files\System\ADO\msado15.dll" \ rename("EOF", "EndOfFile") the path is OS...
4
by: Alvin SIU | last post by:
Hi all, I have 6 tables inside a MS Access 2003 mdb file. I want to convert them as DB2 version -8 tables in AIX 5.2. I have exported them as 6 XML files. The XML files look fine. Each...
6
by: provor | last post by:
Hello, I have the following code that I am using when a user presses a button to import an excel file into a table. The code is hard coded to point to the correct table. This works great for this...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.