Solved

Import Into Access

Posted on 2001-09-13
2
173 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 6

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now