Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Import MS Access data into MS Excel using VBA...

Hello all,

I've been left with the dubious task of importing Microsoft Access data into
an Microsoft Excel spreadsheet using ADO. Unfortunately, it's been years
since I had to do this type of project. Would anyone be so kind as to point
me to a website that shows the code to do this type of stuff? I will be
using ADO. It seems to me that I used DAO the last time I had to do this
type of import, but again that was years ago. I'm sure things have changed
a lot in a few years.


Thanks a bunch,

Steve

--
A Microsoft Certified System Engineer is to computing what a McDonalds
Certified Food Specialist is to fine cuisine.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Import MS Access data into MS Excel using VBA...

I have a page on my site Steve
See also the link to OLE's site on the page

http://www.rondebruin.nl/accessexcel.htm



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Steve Thompson" wrote in message ...
Hello all,

I've been left with the dubious task of importing Microsoft Access data into
an Microsoft Excel spreadsheet using ADO. Unfortunately, it's been years
since I had to do this type of project. Would anyone be so kind as to point
me to a website that shows the code to do this type of stuff? I will be
using ADO. It seems to me that I used DAO the last time I had to do this
type of import, but again that was years ago. I'm sure things have changed
a lot in a few years.


Thanks a bunch,

Steve

--
A Microsoft Certified System Engineer is to computing what a McDonalds
Certified Food Specialist is to fine cuisine.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Import MS Access data into MS Excel using VBA...

Ron de Bruin wrote:

I have a page on my site Steve
See also the link to OLE's site on the page

http://www.rondebruin.nl/accessexcel.htm




Thank you Ron, I appreciate it.

Steve
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Import MS Access data into MS Excel using VBA...

Steve Thompson wrote:

Hello all,

I've been left with the dubious task of importing Microsoft Access data
into an Microsoft Excel spreadsheet using ADO. Unfortunately, it's been
years since I had to do this type of project. Would anyone be so kind as
to point me to a website that shows the code to do this type of stuff? I
will be using ADO. It seems to me that I used DAO the last time I had to
do this type of import, but again that was years ago. I'm sure things have
changed a lot in a few years.


Thanks a bunch,

Steve


Ron,

I'm getting an error 3705; See below (watch out for linw wrap). Do you know
how to fix this?


Sub ImportDataTwo()
Dim conConnection As ADODB.Connection
Dim lngColIndex As Long
Dim rstRecordset As ADODB.Recordset
Dim strFullPath As String
Dim strTableName As String
Dim rngTarget As Range
Dim strSQL As String

'Set rngTarget = rngTarget.Cells(1, 1)
strFullPath = "C:\Source\VB6\DMR\Valero.mdb"
strTableName = "MonthlyDataForExcel"


Set conConnection = New ADODB.Connection
conConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database
Password=Administrator; Data Source=" & strFullPath & ";Persist Security
Info=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Engine Type=5"

Set rstRecordset = New ADODB.Recordset

With rstRecordset
.Open strTableName, conConnection, adOpenStatic, , adCmdTable

'Run-time error '3705':
'
'Operation is not allowed when the object is open.
.Open "SELECT * FROM " & strTableName & ";" & conConnection & " , ,
adCmdText" ' < -- Error Here

rngTarget = "A1"

For lngColIndex = 0 To rstRecordset.Fields.Count - 1
rngTarget.Offset(0, lngColIndex).Value =
rstRecordset.Fields(lngColIndex).Name
Next

rngTarget.Offset(1, 0).CopyFromRecordset rstRecordset
End With

rstRecordset.Close
Set rstRecordset = Nothing

conConnection.Close
Set conConnection = Nothing
End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default Import MS Access data into MS Excel using VBA...

"Steve Thompson" wrote:

I'm getting an error 3705; See below (watch out for linw wrap). Do you know
how to fix this?

With rstRecordset
.Open strTableName, conConnection, adOpenStatic, , adCmdTable
.Open "SELECT * FROM " & strTableName & ";" & conConnection & " , ,
adCmdText" ' < -- Error Here


I don't think you can open the same recordset twice.
It looks like both .Open... lines try to do the same thing, so you only need
one.

--
urkec


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Import MS Access data into MS Excel using VBA...

urkec wrote:

"Steve Thompson" wrote:

I'm getting an error 3705; See below (watch out for linw wrap). Do you
know how to fix this?

With rstRecordset
.Open strTableName, conConnection, adOpenStatic, , adCmdTable
.Open "SELECT * FROM " & strTableName & ";" & conConnection & " ,
,
adCmdText" ' < -- Error Here


I don't think you can open the same recordset twice.
It looks like both .Open... lines try to do the same thing, so you only
need one.


My mistake. the line ".Open strTableName, conConnection, adOpenStatic, ,
adCmdTable" should have been delete in my post.

But even still, I get the same error. Any siuggestions?

Steve
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default Import MS Access data into MS Excel using VBA...

"Steve Thompson" wrote:

urkec wrote:

"Steve Thompson" wrote:

I'm getting an error 3705; See below (watch out for linw wrap). Do you
know how to fix this?

With rstRecordset
.Open strTableName, conConnection, adOpenStatic, , adCmdTable
.Open "SELECT * FROM " & strTableName & ";" & conConnection & " ,
,
adCmdText" ' < -- Error Here


I don't think you can open the same recordset twice.
It looks like both .Open... lines try to do the same thing, so you only
need one.


My mistake. the line ".Open strTableName, conConnection, adOpenStatic, ,
adCmdTable" should have been delete in my post.

But even still, I get the same error. Any siuggestions?

Steve



Sorry, I overlooked that.

This is the syntax for ADO recordset.Open:

recordset.Open Source, ActiveConnection, CursorType, LockType, Options


Source is your SQL statement ("SELECT * FROM " & strTableName),
ActiveConnection is conConnection and Options is adCmdText, so your call
could look like this:

..Open Source:="SELECT * FROM " & strTableName, _
ActiveConnection:=conConnection, _
Options:=adCmdText

Or your procedyre like this:


Sub ImportDataTwo()

Dim conConnection As ADODB.Connection
Dim lngColIndex As Long
Dim rstRecordset As ADODB.Recordset
Dim strFullPath As String
Dim strTableName As String
Dim rngTarget As Range
Dim strSQL As String

strFullPath = "C:\Source\VB6\DMR\Valero.mdb"
strTableName = "MonthlyDataForExcel"

Set conConnection = New ADODB.Connection
conConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database
Password=Administrator; Data Source=" & strFullPath & ";Persist Security
Info=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Engine Type=5"

Set rstRecordset = New ADODB.Recordset

With rstRecordset
..Open Source:="SELECT * FROM " & strTableName, _
ActiveConnection:=conConnection, _
Options:=adCmdText
End With

Set rngTarget = Range("A1")

For lngColIndex = 0 To rstRecordset.Fields.Count - 1
rngTarget.Offset(0, lngColIndex).Value = rstRecordset.Fields(lngColIndex).Name
Next

rngTarget.Offset(1, 0).CopyFromRecordset rstRecordset


rstRecordset.Close
Set rstRecordset = Nothing

conConnection.Close
Set conConnection = Nothing
End Sub


Hope this helps some.

--
urkec
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
import access data into excel George Applegate[_2_] Excel Discussion (Misc queries) 1 April 18th 08 10:13 PM
import data from access to excel George Applegate[_2_] Excel Worksheet Functions 1 April 18th 08 02:13 PM
How do I import hyperlink data from Access into Excel? Dennis Excel Discussion (Misc queries) 0 February 23rd 06 03:29 PM
Import Access data into Excel - Looking for programmer Harry[_7_] Excel Programming 1 February 13th 05 05:47 PM
Access Data import in Excel with QueryDefs Laurent M Excel Programming 1 January 21st 05 12:37 AM


All times are GMT +1. The time now is 03:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"