473,503 Members | 3,171 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 8790

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
2526
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
6681
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
9457
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
1282
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
3692
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
12057
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
4111
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
10296
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
26278
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
7188
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7063
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7258
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7313
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6970
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
4663
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3156
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3146
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.