473,566 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 ADOExcelToSQLSe rver()
Dim Cn As ADODB.Connectio n
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.Wo rksheets("FOGLI O1")

Set Cn = New ADODB.Connectio n
Cn.Open "Driver={SQ L Server};Server= " & ServerName & ";Database= "
& DatabaseName & _
";Uid=" & UserID & ";Pwd=" & Password & ";"

rs.Open TableName, Cn, adOpenKeyset, adLockOptimisti c

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...simila r
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 2162
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
TransferSpreads heet?? 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
2100
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 3rd party automation tools would be greatly appreciated. Raymond ---------------------------(end of broadcast)---------------------------
6
13116
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 spreadsheet. I'm having trouble with my code at the point at which it hits ".ReadRecords" -- the module just runs and runs without generating anything. I've...
1
3937
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 without any problems but how do I get the photo to export with it. Is this possible. Thanks in advance
7
5130
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 probleme? To export my tables i use folowing code: StTotaal = stLocatieName & "\Archief\" & Year(Date) & Month(Date) & Day(Date) & "_Gegevens.xls" ...
10
14717
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 vba is a little confusing for me since i have never used it plus i have lost touch with vb coding since last 8 monhts. anywayz, my problem is i'm...
5
16327
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 have tried the MS kb 210486 and successfully got the import/export to work with a sample table, but only the first record. I do not wish to impost...
1
10473
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 trying to export to Excel using a command in an Access Form. RowID strFY AccountID CostElementWBS 1 2008 1 ...
1
2848
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 Objects. This database is used to produce passes. I want to export one record from the dartabase including the picture into a format that can be easily...
3
7536
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 like garbage. I have maximize and minimize buttons on the left side of the excel spreadsheet that I don't want. I want separate tabs on the...
0
7584
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7888
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8108
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7644
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6260
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2083
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.