Solved

Import Into Access

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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 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…
Suggested Courses
Course of the Month10 days, 4 hours left to enroll

623 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