473,416 Members | 1,760 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,416 software developers and data experts.

Getting data from excel spreadsheet column into access table

Hi everyone... I am pulling my hair out trying to do this, and was
wondering if someone could give me some assistance...
I have an Excel spreadsheet containing several worksheets. I'd like to
be able to take all of the data from the second column (B) of each
worksheet and append that raw data to an access table. The columns in
the spreadsheet do not have headers for use as field names (it's my
assumption that my table should have a field named "F2")...
This action needs to take place on an event - I need to be able to grab
updated data out of the spreadsheet at any time (a one-time import
won't work).
I only need the data from the second column, and it's all text data.
I've looked into several different methods already, and I think the ADO
connection is the best way to go, but I'm having no luck establishing
the connection to the spreadsheet and/or extracting any data from it.
Any help (or code examples) would be greatly appreciated. Thanks!
PS - here's what I've used to establish my connection to the excel file
- I get an error: "Could not find installable ISAM"... The path to my
excel dll file is correct in the registry.
Once I get past the connection problem, I have no idea how to append
the data from the spreadsheet to the database. Anyone's help would be
GREATLY appreciated. Thanks!
-Terry

Dim xlpath As String
Dim cn As New ADODB.Connection

xlpath = "c:\test\book1.xls"

With cn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "Data Source=" & xlpath & ";Extended
Properties=Excel 8.0;HDR=No;"
.CursorLocation = adUseClient
.Open
End With

Dec 9 '05 #1
6 6321
Setup a linked table to the spreadsheet. You need to link to the
spreadsheet three times, one for each sheet. Then you can make a union
query that pulls the second column from each sheet. then update based
on that union query.

Mike

Dec 9 '05 #2
Thanks for the suggestion, Mike... I was sort of hoping to avoid using
the linked table for one reason - other worksheets could be added to
this spreadsheet file at any given notice, and I'd like the ability to
be able to detect this and pull the data from those sheets, as well.
With a link, I'd be required to go in and manually establish another
linked table and add that link to my query. This is the route I
originally was going to go, and if I can't figure out why my ADO
connection isn't working, I'll resort to it. Thanks for your reply!

Dec 9 '05 #3
On 9 Dec 2005 08:28:12 -0800, sy****@yahoo.com wrote:
Hi everyone... I am pulling my hair out trying to do this, and was
wondering if someone could give me some assistance...
I have an Excel spreadsheet containing several worksheets. I'd like to
be able to take all of the data from the second column (B) of each
worksheet and append that raw data to an access table. The columns in
the spreadsheet do not have headers for use as field names (it's my
assumption that my table should have a field named "F2")...
This action needs to take place on an event - I need to be able to grab
updated data out of the spreadsheet at any time (a one-time import
won't work).
I only need the data from the second column, and it's all text data.
I've looked into several different methods already, and I think the ADO
connection is the best way to go, but I'm having no luck establishing
the connection to the spreadsheet and/or extracting any data from it.
Any help (or code examples) would be greatly appreciated. Thanks!
PS - here's what I've used to establish my connection to the excel file
- I get an error: "Could not find installable ISAM"... The path to my
excel dll file is correct in the registry.
Once I get past the connection problem, I have no idea how to append
the data from the spreadsheet to the database. Anyone's help would be
GREATLY appreciated. Thanks!
-Terry

Dim xlpath As String
Dim cn As New ADODB.Connection

xlpath = "c:\test\book1.xls"

With cn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "Data Source=" & xlpath & ";Extended
Properties=Excel 8.0;HDR=No;"
.CursorLocation = adUseClient
.Open
End With

Can't you ise the TransferSpreadsheet method?

In the Click event of a command button:

DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9,
"MyImportTable1","c:\YourPath\SpreadsheetName1.xls ", False,
"WorksheetNameA!B:B"

DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9,
"MyImportTable2", "c:\YourPath\SpreadsheetName2.xls", False,
"WorksheetNameB!B:B"

DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9,
"MyImportTable3", _
"c:\YourPath\SpreadsheetName3.xls", False, "WorksheetNameC!B:B"

Dim strSQL As String
strSQL = "INSERT INTO MyImportTable1 ( F1 )SELECT MyImportTable2.F1
FROM MyImportTable2;"
CurrentDb.Execute strSQL, dbFailOnError
strSQL = "INSERT INTO MyImportTable1 ( F1 )SELECT MyImportTable3.F1
FROM MyImportTable3;"
CurrentDb.Execute strSQL, dbFailOnError

The above will import the data from the 3 named worksheets column B.

Then the 3 tables are combined into the first table.

You can then delete the second and third tables.
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
Dec 9 '05 #4
This would work great (I just tried it and it will work fine) if there
were a way I could determine how many worksheets (and their names) are
in the spreadsheet file automatically. I was also kind of hoping I
could deal with each cell individually so I could test for certain
conditions before placing the data into the table (check for empty/null
cells, etc.). But I could always do that after the data is placed in a
temporary table - I just need a way to see what worksheets the
spreadsheet has and their respective names.

Thanks for your reply, fredg!

Dec 9 '05 #5
Actually, the more I play with it, the more I realize that this method
would work GREAT if I could just determine the number of (and names of)
the individual worksheets beforehand. Then I could dynamically loop
through all of them... Is there a way to just pull the number of
worksheets and their names out of an excel file? thanks!

Dec 9 '05 #6

Something like

' *********** Code Start ***********
Function ListWorkSheets(XLFileName As String) As Variant
Dim loCon As ADODB.Connection
Dim loCat As ADOX.Catalog
Dim loTab As ADOX.Table
Dim varRet As Variant
Dim intX As Integer

Set loCon = New ADODB.Connection
With loCon
.ConnectionString = GetXLConnect(XLFileName)
.Open
End With

Set loCat = New ADOX.Catalog
varRet = Array(0)

With loCat
Set .ActiveConnection = loCon
ReDim varRet(0 To .Tables.Count - 1)
For intX = 0 To .Tables.Count - 1
varRet(intX) = .Tables(intX).Name
Next
End With

Set loCat = Nothing
loCon.Close
Set loCon = Nothing

ListWorkSheets = varRet
End Function
Private Function GetXLConnect(XLFileName As String) As String
Const BASE_CONNECT = "Driver={Microsoft Excel Driver (*.xls)};" _
& "DriverId=790;" _
& "Dbq=<<TAG_SPREADSHEET>>;" _
& "DefaultDir=<<TAG_DIRECTORY>>"
Const TAG_SPREADSHEET = "<<TAG_SPREADSHEET>>"
Const TAG_DIRECTORY = "<<TAG_DIRECTORY>>"

GetXLConnect = BASE_CONNECT
GetXLConnect = Replace(GetXLConnect, TAG_SPREADSHEET, XLFileName,
Compare:=vbTextCompare)
GetXLConnect = Replace(GetXLConnect, TAG_DIRECTORY, Left(XLFileName,
Len(XLFileName) - Len(Dir(XLFileName)) - 1), Compare:=vbTextCompare)
End Function
' *********** Code End ***********

You need a reference to ADOX for this to work.

A test call could be

' *********** Code Start ***********
Sub TestListWorkSheets()
Dim varRet As Variant
Dim intX As Integer

varRet = ListWorkSheets("C:\Book1.xls")

If IsArray(varRet) Then
For intX = LBound(varRet) To UBound(varRet)
Debug.Print varRet(intX)
Next
End If

End Sub
' *********** Code End ***********

--
Terry Kreft

"Syvman" <sy****@yahoo.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
Actually, the more I play with it, the more I realize that this method
would work GREAT if I could just determine the number of (and names of)
the individual worksheets beforehand. Then I could dynamically loop
through all of them... Is there a way to just pull the number of
worksheets and their names out of an excel file? thanks!

Dec 9 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Charles Alexander | last post by:
Hello I'm trying to redisplay and reorganize some data off a huge Excel spreadsheet. I figured it would be easier to manipulate if I dumped the data into MySQL with the help of phpMyAdmin. ...
12
by: jimserac | last post by:
I had previously posted this in an Access forum with negative results so will try here. Although this question specifies an Access database, I also wish to accomplish this with a large MS SQL...
2
by: Fred | last post by:
Hi. How do I import while mapping an excel table to an access table please??? I've searched around and all I can find is a software product or code that does the same thing as the access...
4
by: Martin | last post by:
There is an Access table on the network. 15 users who do not have Access are connected to the network. Is there a way for each user to be able to enter one or more rows containing 3 or 4 columns to...
4
by: Gary Wright | last post by:
I have an Access 2K database split into front and back. Quite often the users want to do some data analysis that I have not created a report for so they want to export some subset of the data into...
13
by: Arno R | last post by:
Hi all, I will have to handle a lot of really 'nice' data in a LOT of Excel sheets. It is all about music files (Billboard top 100) I am afraid there really is a sheet for every year ... (Don't...
3
by: | last post by:
I wrote a class in VB.NET to export the contents of a datagrid to Excel. It works perfectly on my machine, but it fails on my customers' PCs that have identical versions of Win XP (SP1) and Excel...
13
by: nuti | last post by:
Hi all, I am fairly new to VB.I am trying to figure out as how to write a script so that i can read the data from an excel sheet to Access. can u guys please help me out? cheers, nuti
1
by: BigAl.NZ | last post by:
Hi Folks, I am trying to make a database for the classic scenario of customers, products, orders. Its been a wile since i played around with databases. I have four tables: ...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
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.