Solved

Import Into Access

Posted on 2001-09-13
2
178 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

734 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