Solved

Import Into Access

Posted on 2001-09-13
2
176 Views
Last Modified: 2010-05-02
Please could someone give me the code to use the ADO control to import a spreadsheet into an access database table.  The field names on the spreadsheet should correpsond to the field names on the table.

When I use the code below each column is going on a different line in the database.  The field names are the same as the variable names.

The reason I am not using the import manager is because my ultimate aim is to put 7 spreadsheets into one table, where each spreadsheet has different field names.

Thanks in advance

Alistair

Open "V:\assetman\asset management dot com\extracts\assetut05.csv" For Input As #1

Do Until EOF(1)
    Input #1, Code, GEOG, GEOGC, INDC, INDG, INDM, INDX, INDXL, UNAME, SECD, UTYPE, ISIN, ISOCUR, GEOGN, ISINID

    Adodc1.Recordset.AddNew "Code", Code
    Adodc1.Recordset.AddNew "Geog", GEOG
    Adodc1.Recordset.AddNew "Geogc", GEOGC
    Adodc1.Recordset.AddNew "Indc", INDC
    Adodc1.Recordset.AddNew "Indg", INDG
    Adodc1.Recordset.AddNew "Indm", INDM
    Adodc1.Recordset.AddNew "Indx", INDX
    Adodc1.Recordset.AddNew "Indxl", INDXL
    Adodc1.Recordset.AddNew "Name", Name          
    Adodc1.Recordset.AddNew "Secd", SECD
    Adodc1.Recordset.AddNew "Type", UTYPE  
    Adodc1.Recordset.AddNew "ISIN", ISIN
    Adodc1.Recordset.AddNew "IsoCur", ISOCUR
    Adodc1.Recordset.AddNew "Geogn", GEOGN
    Adodc1.Recordset.AddNew "ISINID", ISINID
Loop
end
0
Comment
Question by:Al
2 Comments
 
LVL 1

Accepted Solution

by:
Dan_Morris earned 50 total points
ID: 6479872
With your recordset object, use AddNew once for each record:

'Inside your loop structure:

With ADODC1.Recordset
    .AddNew
    .Fields("Code") = CODE
    .Fields("Geog") = GEOG
    .Fields("Geogc") = GEOGC
    ...    'Set all fields to the appropriate variables.
    .Update
End With


Hope this helps.

Dan

0
 
LVL 7

Expert Comment

by:Nitin Sontakke
ID: 6479915
You are getting the result you have mentioned is because of .AddNew for each column. Although, i have rarely used this technique, as i recollect it is as follows:

adodc1.Recordset.AddNew
adodc1.Recordset.Fields("Code") = Code
all other columns as above.

I am not sure of above. For better way of doing it, fire a INSERT action query on a connection object.

objConn.Execute strQuery

Where, strQuery will be build by you as follows:

strQuery = "INSERT INTO tablename (Code, etc) VALUES ('" & Code & "', ...

I hope you see what i mean...
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question