473,406 Members | 2,849 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,406 software developers and data experts.

dsn-less connection copy data

Ken
How can I copy data from SQL to MS Access using dsn-less connection
and not using SQL DTS? I have this but am stuck. I just want to do
an export but can't figure out how to do a "select into". It pastes
the data in SQL instead of access. The below code will cycle but I
will have to create a table to place the data first. Is there an
easier way.

Sub getTables()
Dim cnnSQL As ADODB.Connection
Dim cnnMSA As ADODB.Connection
Dim strSQL As String
Dim rstSQL As ADODB.Recordset
Dim rstMSA As ADODB.Recordset
Dim strServer As String
Dim strDB As String
Dim i As Long
Dim cnn As ADODB.Connection

strServer = "northwind"
strDB = "pubs"

Set cnnSQL = New ADODB.Connection
Set rstSQL = New ADODB.Recordset
Set cnnMSA = CurrentProject.Connection
Set rstMSA = New ADODB.Recordset
cnnSQL.Open "Provider=sqloledb;Data Source='" & strServer & "';Initial
Catalog='" & strDB & "';Integrated Security=SSPI"
strSQL = "select * from customers"

Set rstMSA = cnnSQL.Execute(strSQL)
Do While Not rstMSA.EOF
For i = 0 To rstMSA.Fields.Count - 1
rstmsa.
'OutPuts Name and Value of each field
Debug.Print rstMSA.Fields(i).Name & ": " & _
rstMSA.Fields(i).Value
Next
rstMSA.MoveNext
Loop
Set cnnSQL = Nothing
Set rstSQL = Nothing

End Sub
Nov 13 '05 #1
2 2205
The following Make-Table query should make a table in your local access
database named "Customers" and import the data from the table "customers" in
catalog "pubs" in datasource "northwind":

SELECT C1.* INTO Customers
FROM [Provider=sqloledb;Data Source='northwind';Initial
Catalog='pubs';Integrated Security=SSPI].customers AS C1;
See if this works for you.

"Ken" <ni************@hotmail.com> wrote in message
news:6a**************************@posting.google.c om...
How can I copy data from SQL to MS Access using dsn-less connection
and not using SQL DTS? I have this but am stuck. I just want to do
an export but can't figure out how to do a "select into". It pastes
the data in SQL instead of access. The below code will cycle but I
will have to create a table to place the data first. Is there an
easier way.

Sub getTables()
Dim cnnSQL As ADODB.Connection
Dim cnnMSA As ADODB.Connection
Dim strSQL As String
Dim rstSQL As ADODB.Recordset
Dim rstMSA As ADODB.Recordset
Dim strServer As String
Dim strDB As String
Dim i As Long
Dim cnn As ADODB.Connection

strServer = "northwind"
strDB = "pubs"

Set cnnSQL = New ADODB.Connection
Set rstSQL = New ADODB.Recordset
Set cnnMSA = CurrentProject.Connection
Set rstMSA = New ADODB.Recordset
cnnSQL.Open "Provider=sqloledb;Data Source='" & strServer & "';Initial
Catalog='" & strDB & "';Integrated Security=SSPI"
strSQL = "select * from customers"

Set rstMSA = cnnSQL.Execute(strSQL)
Do While Not rstMSA.EOF
For i = 0 To rstMSA.Fields.Count - 1
rstmsa.
'OutPuts Name and Value of each field
Debug.Print rstMSA.Fields(i).Name & ": " & _
rstMSA.Fields(i).Value
Next
rstMSA.MoveNext
Loop
Set cnnSQL = Nothing
Set rstSQL = Nothing

End Sub

Nov 13 '05 #2
Sorry for posting late but it does not work. Any other ideas.

Sub subtest()
Dim strsql As String
Dim cmd As New ADODB.Command

strsql = "SELECT C1.* INTO Customers FROM [Provider=sqloledb;Data
Source='northwind';Initial Catalog='pubs';Integrated
Security=SSPI].customers AS C1;"

With cmd
.ActiveConnection = CurrentProject.Connection
.CommandText = strsql
.CommandType = adCmdText
.Execute
End With

cmd.Close
Set cmd = Nothing
Debug.Print "done"
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #3

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

Similar topics

3
by: McCool | last post by:
How can I get the deployment project to setup a DSN pointing to an Access DB after installation takes place? Also, is there a way to kick off a vbs script after installation takes place through...
3
by: emily | last post by:
Perhaps this has already been answered. If so, I apologize. I'm a newbie at this stuff. I have a DTS package to import some Visual Foxpro data. Yes, I said Visual Foxpro. :) The DTS package...
6
by: Andi Reisenhofer | last post by:
Hallo C# folks, Somebody know how to create a ODBC DSN dynamically in c# program. Also interesting for me would be the connectionstring for an Access Database. Thinks a lot Andreas
4
by: Steve Sweales | last post by:
I'm trying to find some code on how to create a DSN using C# and SQLConfigDataSource. Can anybody help me please, before I tear my hair out!! *** Sent via Devdex http://www.devdex.com ***...
8
by: DerekS | last post by:
Hi, I've been pulling my hair out trying to write a simple method to programatically create a system DSN with all parameters on a remote machine. I have ensured I have the correct permissions on...
3
by: Niks | last post by:
Hi, I need to connect to SQL server Database using a System DSN. Can anyone tell me how to connect to SQL Server using DSN in ASP.NET (VB.Net). Using a Try Catch block. Does anyone know how to...
14
by: kdv09 | last post by:
Hi! I'm looking for some help in fixing my screwup: I've got C++ app which reads MDB database, using MFC CDatabase and CRecordset derived classes. I had it working OK on development PC (Win XP...
0
by: Neo | last post by:
Hello All, ODBCAD32.exe launches DSN Setup. But then I have to select DSN and click configure to configure DSN. Is there any way, I could invoke configuration dialog box for particular DSN...
0
by: senthildb2 | last post by:
Hi there, I want to create DSN for DB2 database through my VB application. I have installed DB2 v8.2 with FixPack6.0 ESE. (The actual version shown in Control Center is DB2 V8.1.13.193) The...
4
by: bytesbytes | last post by:
Hi, Im using VB6.0, Crystal report 10 and MSaccess Database. I was using Crystal report 6 and later upgraded to CR10. In VB6 i used DSN like .Connect = "DSN=DBName" & ";UID=admin;PWD=;" Now in...
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: 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?
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:
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...

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.