473,413 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

Reading Excel Recordset

77
Hi,

I am trying to import data from an excel file into my database.

I am able to create an ado connection and then create a recordset of the excel data..

However, I am stuck at importing that data all at once in my access 2003 db as I am not able to find any property to enable this.. Instead, I have to loop through the data and then update the table one record at a time (which is time consuming)..

Is there any way this can be accomplished?

Thanks.
Aug 28 '08 #1
11 6954
Stewart Ross
2,545 Expert Mod 2GB
Hi. Why not link the Excel table directly as a linked table? You will then be able to use it in queries and so on like any other table.

If this is not an option then use the Transferspreadsheet method to import your spreadsheet. Look up the help file (from VBA) to get the exact syntax.

The following extract from the helpfile shows how it can be used:

Example
The following example imports the data from the specified range of the Lotus spreadsheet Newemps.wk3 into the Microsoft Access Employees table. It uses the first row of the spreadsheet as field names.

DoCmd.TransferSpreadsheet acImport, 3, _
"Employees","C:\Lotus\Newemps.wk3", True, "A1:G12"
-Stewart
Aug 28 '08 #2
yaaara
77
Hi and Thanks for the prompt reply.

The transferspreadsheet functionality may not work as I need to read the excel file and then also join the data with some more fields in another table to reach to a final recordset which is to be inserted into a separate table..

Isn't there any method by which we can simply copy this recordset into the table recordset and update the table?

Thanks.
Aug 28 '08 #3
Stewart Ross
2,545 Expert Mod 2GB
Sorry, no there is not. Why not just transfer the other data separately into another table then combine them in Access itself? Otherwise you will have to be content with traversing the Excel data row by row in your loop as at present.

-Stewart
Aug 28 '08 #4
yaaara
77
Hello and thanks again for the reply..

Could you also please elaborate as to what you mean by "transfer the other data separately into another table then combine them in Access itself?"

I'm not sure I understood what you meant... sorry :-(

Sorry, no there is not. Why not just transfer the other data separately into another table then combine them in Access itself? Otherwise you will have to be content with traversing the Excel data row by row in your loop as at present.

-Stewart
Aug 28 '08 #5
Stewart Ross
2,545 Expert Mod 2GB
Assuming that there are fields in common between the two Excel datasets you could use an Access Query to join the two tables together as necessary. I am not convinced that there is any need at all to form a third table from the two combined tables - the norm is to use queries as 'virtual tables' or views of your data which avoids the need to redundantly create a third table to join two existing ones. Even if there was a need for the conjoined table, you could use an Access Maketable query to do that for you.

It will be different if you are combining data according to some local rule or algorithm which does not rely on fields in common (for example, add data from sheet 2 to every third row of sheet 1); you would have to programme that yourself.

-Stewart
Aug 28 '08 #6
yaaara
77
Actually, the data is combined based on some calculations on the tables, which i'm not sure would be possible using the access query.. The entire data is ready to be fetched into the access table (to re-iterate, the final recordset comprises of the excel data and access data).. all is required is a method to fetch the data into the access table in one go.. just like the data may be fetched into excel from access in one go using "CopyFromRecordset" method...

Assuming that there are fields in common between the two Excel datasets you could use an Access Query to join the two tables together as necessary. I am not convinced that there is any need at all to form a third table from the two combined tables - the norm is to use queries as 'virtual tables' or views of your data which avoids the need to redundantly create a third table to join two existing ones. Even if there was a need for the conjoined table, you could use an Access Maketable query to do that for you.

It will be different if you are combining data according to some local rule or algorithm which does not rely on fields in common (for example, add data from sheet 2 to every third row of sheet 1); you would have to programme that yourself.

-Stewart
Aug 28 '08 #7
Stewart Ross
2,545 Expert Mod 2GB
...which is what TransferSpreadsheet does, as mentioned above.

CopyfromRecordset takes the results of any existing recordset - from a single table through to a complex query joining and calculating in any number of ways - and transfers the recordset to Excel. TransferSpreadsheet does the same thing in reverse - you specify the worksheet you want to transfer, and it takes the specified worksheet (or range) and imports that into Access in one step. Please look up the TransferSpreadsheet help data as I suggested.

If you need to perform joins on the Excel data you will have to do those first, before you apply Transferspreadsheet.

Otherwise, I can make no further suggestions on this topic. I have covered all the options I know of: link the worksheet directly, import it using TransferSpreadsheet, or use the loop-processing method you are already embarked upon.

-Stewart
Aug 28 '08 #8
yaaara
77
Thanks for all the help... I'll surely check out the options and see what works out for me.. Will surely let you know the results..

Many Thanks.
Aug 28 '08 #9
NeoPa
32,556 Expert Mod 16PB
As Stewart says, you can either link the spreadsheet as a table, or import the data into a table.

That done, you can do the processing you need with the Excel side of things "converted" to Access thereby allowing any data manipulation to be done in Access and, of course, produce your results in Access.

Welcome to Bytes!
Aug 28 '08 #10
I have been able to work with linked spreadsheets in access while opening them up through code and still look at them by putting them in share mode. Works like a charm.
Jun 15 '09 #11
NeoPa
32,556 Expert Mod 16PB
Good to hear from you Amy.

Welcome to Bytes!
Jun 15 '09 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Derk | last post by:
I have an VB App that reads an Excel Sspreadsheet and it seems to having problems determining the data type of a column. The column in question has alpha numeric content eg S001, B123 or 1234. I am...
1
by: Hemanth | last post by:
Hello there, Could someone pls give me pointers (or examples) on how to use PHP (installed on a linux) to read & write MS Excel spreadsheets. So far I've been converting a spreadsheet to text...
6
by: Paul | last post by:
I was wondering if anyone has had an issue where using vba code to read an excel file and import the data into an access table some records are not imported from the excel file. It seems looking at...
7
by: Jean | last post by:
Hello, I have a form that performs a search, according to criteria that a user enters into the text boxes. When the user clicks on „Search", a SQL string (say strSQL) is built up with the...
2
by: Phoebe | last post by:
Hi, Good Day! I've a coding which Open Excel File and save it into a recordset. But the below coding "died" when reached the SQL statement. Can someone help? Thanks in advanced. rgds...
6
by: simchajoy2000 | last post by:
Hi, So I do actually know how to read excel into VB.NET using the following approach: With oConn2 .ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & FilePath & ";Extended...
9
by: dba123 | last post by:
I need some help and direction on what classes and an example or two (article) on how to read an Excel Worksheet and insert one column into a database table column. I am using .NET 2.0 only. What...
0
by: raghunadhs | last post by:
hi Guys! i able to read data from excel through record set . the only problem is suppose if i want to read the data in excel of a particular range say "A2:G5" the record set is able...
2
by: sbettadpur | last post by:
hello everybody, can anybody have solution for reading excel from php. my requirement is like this : Initially i have to read the excel file and i need to insert that values into database...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.