473,782 Members | 2,485 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 8821

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.TransferT ext 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 HeadingNameExam ple

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********@hotm ail.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********@hot mail.comwrote in message
news:11******** **************@ p79g2000cwp.goo glegroups.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.TransferT ext 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 HeadingNameExam ple

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********@hotm ail.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
2542
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 files into a single table. I have no idea where to start. Any ideas. The Pig
1
6703
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 database stats: Path: C:\Database (contains the database and all the text files to be imported) Text files to import: (SampleData4.txt and SampleData3.txt as testing examples)
4
9480
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 e.g. must field1, field2, filed3 etc correspond to col1, col2, col3 on the table? or can I state somewhere which columns in the text file correspond to which table columns. I actually need col1, col2, col5 and col6 from the text file to populate...
0
1303
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 further in that certain files contain different variations of a larger group for example a group is EB33. My function now would import the file and I would have a table name EB33. In that file can contain two different variables of that call them EB33A...
3
3717
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 - and dump everything into a table. The problem is once I have the data imported into a new table, I can't do much with it. If I try to run an Append query and insert data from the new table into an existing table, the query fails - "Error...
2
12115
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 command button, nothing happens.Here is my code: Private Sub cmdStartImport_Click() Dim rst As ADODB.Recordset Dim strNewTable As String Dim strFileType As String On Error GoTo ErrorHandler
1
4123
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 dependent - what if I run on some other PC but the msado15.dll is not specificed in the path specified? for this case - #import "c:\Program Files\Common Files\System\ADO\
4
10326
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 record is embeded by a tag which is the table name.
6
26330
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 one table. My problem is I have two buttons I want to use this code for for the two buttons would put the data in different tables. I have tried copying and changing a few things and nothing will work for me. The code is set up in a module and then I...
0
10313
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10080
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9944
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6735
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4044
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3643
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.