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

Excel -> Access Table

Hi,

I would like to be able to using VBA from an Excel macro - go through
each line in my spreadsheet and add to a database.

I know that this can be done via the import external data tool in
access but the final solution i am working towards will allow the user
to select columns from randomly formatted datasets in excel.

I already have code that loops through every row in my excel file to
format it correctly so it isn't the loop i am worried about. It is the
actual insert code from vba i need to use.

Preferably without using a DSN connection if possible and instead
naming the direct route to the database - since this is going to be
stored over the network.

Regards,

Andy

Oct 31 '06 #1
1 1898
You can use either DAO or ADO with DSN-less connection in your Excel's VBA
code to send data from the sheets to Jet database (*.mdb). psuedo-code like
this:

Dim cn As ADODB.Connection
Set cn=New ADODB.Connection
cn.Open yourConnectionStringToTheDatabase

''In your loop for each row of the sheet
For each sheetrow of the sheet
cn.Execute "INSERT INTO theTable (Col1, Col2....) VALUES (cell1Value,
cell2Value...)"
Or
cn.Execute "UPDATE theTable SET ....WHERE..."
Next row

cn.Close

Or you can open a RecordSet based a table in the database. Than populate the
RecordSet with data from Excel sheet and do the update the RecordSet back to
the database at the end.

With this kind of approach, you have the full control and the flexibility to
match user selected columns to certain table in the database and do the data
transfer.

"Patonar" <pa*****@aston.ac.ukwrote in message
news:11**********************@m7g2000cwm.googlegro ups.com...
Hi,

I would like to be able to using VBA from an Excel macro - go through
each line in my spreadsheet and add to a database.

I know that this can be done via the import external data tool in
access but the final solution i am working towards will allow the user
to select columns from randomly formatted datasets in excel.

I already have code that loops through every row in my excel file to
format it correctly so it isn't the loop i am worried about. It is the
actual insert code from vba i need to use.

Preferably without using a DSN connection if possible and instead
naming the direct route to the database - since this is going to be
stored over the network.

Regards,

Andy

Oct 31 '06 #2

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

Similar topics

0
by: I Decker | last post by:
Hi all, Hope this is the right group. I am writing a program in c# to open create an excel document, enter some data, save it and then email it as an attachment. I have successfully created...
6
by: Matthew Wieder | last post by:
I have the following requirements: Build a stand-alone C# application that asks the user to click in a cell in an Excel spreadsheet, and then displays the address of that cell in the C#...
22
by: Howard Kaikow | last post by:
There's a significant problem in automating Excel from VB .NET. Reminds me of a problem I encountered almost 3 years ago that was caused by the Norton Auntie Virus Office plug-in. Can anybody...
18
by: lgbjr | last post by:
Hi All, I have a VB.NET app that, among other things, writes data to Excel. I am having trouble getting the Excel process to terminate after I quit Excel. I found an article related to this...
16
by: LP | last post by:
Hello, I am trying to use .NET with Excel. I installed Office 2003 and selected ..NET programming suport option, so it installed all those PIA, as MS sugests. But I can not find a way to destroy...
7
by: Alain \Mbuna\ | last post by:
Hi everybody. In my program I have some data that is calculated after some input from the user. I have written some code that opens an Excel workbook, with 5 worksheets and the calculated data...
16
by: alexia.bee | last post by:
Hi all, In some weird reason, excel instance won;t die if i remove the comment from 4 lines of setting values into struct. here is a snipcode public...
9
by: Doug Glancy | last post by:
I got the following code from Francesco Balena's site, for disposing of Com objects: Sub SetNothing(Of T)(ByRef obj As T) ' Dispose of the object if possible If obj IsNot Nothing AndAlso...
1
by: fakehitswizard | last post by:
this is the correct way to close excel with C#. I've seen alot of other bogus posts ALL over the web that don't work, how frustrating. string savepath; bool foundPID; int ourPID = 0; int...
7
by: =?Utf-8?B?VGVycnkgSG9sbGFuZA==?= | last post by:
I have a vb.net app that opens an excel worksheet, reads data and then closes the sheet. Im noticing that the Excel process is still running after I have closed and disposed of my excel objects. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.