Solved

Import Into Access

Posted on 2001-09-13
2
177 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 9

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Validating VB6 Function 19 68
Access 2013 combo box not working 3 58
Automatic Email Reminder 4 71
MS SQL Update query with connected table data 3 59
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

740 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