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

EXPORT ACCESS TO SQL DATABASE RECORD BY RECORD...



I use this code to update a sql database from excel to sql...
Now i would want to arange this code to export an Access table into
sql databse...

Sub ADOExcelToSQLServer()
Dim Cn As ADODB.Connection
Dim ServerName As String
Dim DatabaseName As String
Dim TableName As String
Dim UserID As String
Dim Password As String
Dim rs As ADODB.Recordset
Dim NoOfFields As Integer
Dim Row As String
Dim ws As Worksheet
Set rs = New ADODB.Recordset
ServerName = "USER-E114319F02"
DatabaseName = "northwind"
TableName = "Employees"
UserID = ""
Password = ""
Row = 1

Set ws = ThisWorkbook.Worksheets("FOGLIO1")

Set Cn = New ADODB.Connection
Cn.Open "Driver={SQL Server};Server=" & ServerName & ";Database="
& DatabaseName & _
";Uid=" & UserID & ";Pwd=" & Password & ";"

rs.Open TableName, Cn, adOpenKeyset, adLockOptimistic

While Not ws.Range("A" + Row) = ""

rs.AddNew

rs![LASTName] = ws.Range("A" + Row).Value
rs![FIRSTName] = ws.Range("B" + Row).Value
rs![Title] = ws.Range("C" + Row).Value
rs.UpdateBatch

Row = Row + 1

Wend
rs.Close
Set rs = Nothing
Cn.Close
Set Cn = Nothing
End Sub
'''''''''''''''''''''''''''''''''''''''''
In effect insted to use column and cell from sheet use column and
record from access table...
Important for me is to make a code write record by record...similar
the block in code:

While Not ws.Range("A" + Row) = ""

rs.AddNew

rs![LASTName] = record of access table
rs![FIRSTName] = record of access table
rs![Title] = record of access table
rs.UpdateBatch

Row = Row + 1

Wend

*** Sent via Developersdex http://www.developersdex.com ***
Jun 18 '06 #1
1 2144
Wait, are you importing Excel data to SQL Server, or to Acccess
or...??

If so, why would you want to import a record at a time, if all the
records are going into the same table? Why not use
TransferSpreadsheet?? Unless you need to do complex data checking on
each record or something?

Maybe you should explain further... why will this not work for you? Or
do you just like making your own life difficult?

Jun 19 '06 #2

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

Similar topics

1
by: Raymond | last post by:
Need to export an existing M$ Access 97 database to Postgres. Tuples must be filtered as I am using sequences and other constraints. Help from anyone that has experience with this or know of...
6
by: Robin Cushman | last post by:
Hi all, I need some help -- I'm working with an A2K database, using DAO, and am trying to read records into a Crystal Report and then export it to a folder on our network as an Excel...
1
by: Elaine Shore | last post by:
I have an Access 2000 database where each record has it's own photo stored as an OLE object. I am trying to export a report (of all the records) to HTML format. The data for each record exports...
7
by: Keon | last post by:
Hoi, I'm using a database with alot of records in 1 table (more than 3000). If i want to export this table to excel i only get it till record 2385. Do someone know how i can solve this...
10
by: Neil | last post by:
Hi guyz, just trying out this google feature so if i post if in the wrong area i appologize. now to my question. BTW i'm new to access programming, i've done a little vb6.0 and vb.net but access...
5
by: bhodgins | last post by:
Hi, I am new on here, and had a newbie question that I am stumped with. I am not new to access, but am new to VB. I am trying to export BLOBs from a field called photo to external jpeg files. I...
1
by: CoolFactor | last post by:
MY CODE IS NEAR THE BOTTOM I want to export this Access query into Excel using a command button on an Access form in the following way I describe below. Below you will find the simple query I am...
1
by: davidwelli | last post by:
Hello, I have a Access 200 format database that contains contact details and a picture for each record. The contact details are held in one table and the images are held in another as OLE...
3
by: jmarcrum | last post by:
I want to export a report (that contains two separate queries, 1. Current year data, and 2. split-year data) from access into excel, but everytime I run my code and export the data to excel, it looks...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.