Import CSV but splitting the import data into two tables 
Author Message
 Import CSV but splitting the import data into two tables

I have a .CSV file with has two sets of data, for
example:

"CustomerID","CustomerName","CustomerAddress"
132,"J Blog","1 London Street,London"
"ProductID","ProductName","Qty"
10056,"13A Socket",3
10008,"Plugs",1

Brake down of the file:

-------------------------------------------------
Customer Information:

"CustomerID","CustomerName","CustomerAddress"
132,"J Blog","1 London Street,London"

Bought:

"ProductID","ProductName","Qty"
10056,"13A Socket",3
10008,"Plugs",1
-------------------------------------------------

What I would like to do is select the csv file and run a
script which will import the data in the file - BUT (here
is the bit I don't know would work) - I would like to put
the Customer Information data in one table and the things
that customer has bought in another table.

Is this possible, if so how would I go about it?  

Thanks in advance.

Will



Wed, 05 Oct 2005 18:01:16 GMT  
 Import CSV but splitting the import data into two tables

See

Open the two tables as Recordsets

http://www.mvps.org/access/downloads/clsReadTextFile.txt
This gets the file into a variable on a line by line basis

Check the line - contents \ format \ count them

and .Addnew - - - - - - - .Update into the appropriate rst

I use this on a number of projtects and it seems to be A1

Mike

--
Posted via http://dbforums.com



Thu, 06 Oct 2005 03:56:33 GMT  
 Import CSV but splitting the import data into two tables

Is the two sets of data specific for only one customer per file?

Here's a snippet:
Open the file
Skip the first and third lines since they are your header rows.
Send the second line to another sub to extract the Customer field data.
Send everything beyond the third row to another sub to process the
Bought data.

  Dim intInFile As Integer
  Dim strTmp As String
  Dim intCounter As Integer

  ' Get free file handle
  intInFile = FreeFile

  ' Open the file for input, read it, and close it
  Open strInFile For Input As intInFile

  ' Go through our file line by line
  Do Until EOF(intInFile)

    ' Increment our counter
    intCounter = intCounter + 1

    ' Read the line
    Line Input #intInFile, strTmp

    Select Case intCounter
        Case 1, 3:  'skip the header rows
        Case 2: ' Append the tblCustomer_Information data
            Call Append_Customer_Information(strTmp, ",")
        Case Else: ' Append the tblBought data
            Call Append_Bought(strTmp, ",")
    End Select

  Loop

  ' Close our file
  Close #intInFile

(strTmp, ",") - the comma would indicate the delimeter used but keep in
mind that you are storing a comma in one of your text fields - so a few
extra measures will be needed to parse the comma separated row.

Matt

--
Posted via http://dbforums.com



Fri, 07 Oct 2005 21:06:03 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Importing csv into linked table problem

2. Help Importing a CSV into a Linked Table.

3. Importing a CSV file into an MS Access 2.0 table using VB 4.0

4. Importing "csv" file into existing table

5. Importing .CSV to table

6. Importing CSV file into Oracle Tables

7. Import CSV file into Access table using ADO

8. Importing a CSV table

9. Import CSV Doc in VB to Access Table

10. VBA - Import Data from CSV File

11. Import Ascii (Textual) Data with Import Wizard

12. Syntax for importing data into an Access table from an ODBC data source

 

 
Powered by phpBB® Forum Software