Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Problem with the following code

Can anyone tell me what may be wrong with the following code?
It generates an error when it tries to execute the .Open for the recordset.
I am trying to connect to the database, open the table, and bring data back
to an excel spreadsheet. Also, is the same procedure used to open a query
that is stored in the access database that is used to open a table.

Any help would be greatly appreciated.
Thanks
Vince


Dim cn As ADODB.Connection, rs As ADODB.Recordset, r As Long, c As Long
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.Oledb.4.0; " & _
"Data Source=C:\Access Data\DoctorBlades.mdb;"

Set rs = New ADODB.Recordset

With rs
.Open "tblDoctorBlades", cn, adOpenDynamic, adLockOptimistic
End With

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default Problem with the following code

Give this a shot.

Dim cn As ADODB.Connection, rs As ADODB.Recordset, r As
Long, c As Long

cn.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0; "
_
& "Data Source=C:\Access Data\DoctorBlades.mdb;"
cn.Open
cn.CursorLocation = adUseClient
rs.Open "tblDoctorBlades", cn, adOpenDynamic,
adLockOptimistic

-----Original Message-----
Can anyone tell me what may be wrong with the following

code?
It generates an error when it tries to execute the .Open

for the recordset.
I am trying to connect to the database, open the table,

and bring data back
to an excel spreadsheet. Also, is the same procedure

used to open a query
that is stored in the access database that is used to

open a table.

Any help would be greatly appreciated.
Thanks
Vince


Dim cn As ADODB.Connection, rs As ADODB.Recordset, r As

Long, c As Long
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.Oledb.4.0; " & _
"Data Source=C:\Access Data\DoctorBlades.mdb;"

Set rs = New ADODB.Recordset

With rs
.Open "tblDoctorBlades", cn, adOpenDynamic,

adLockOptimistic
End With

.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default Problem with the following code

I believe this is more like what u are trying to do. U
will need to sub the dbname, tablename, and fieldname for
this code to work.


Dim cn As ADODB.Connection, rs As ADODB.Recordset, r As
Long, c As Long
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.Oledb.4.0; " & _
"Data Source=d:\Db10.mdb;"

Set rs = New ADODB.Recordset
Dim strsql As String
strsql = "SELECT [Company] FROM Customers "
rs.Open strsql, cn

Do Until EOF = True
rs.MoveFirst
ActiveCell = rs![Company]
ActiveCell.Offset(rowoffset:=1).Activate
rs.MoveNext
Loop
rs.Close
cn.Close
-----Original Message-----
Can anyone tell me what may be wrong with the following

code?
It generates an error when it tries to execute the .Open

for the recordset.
I am trying to connect to the database, open the table,

and bring data back
to an excel spreadsheet. Also, is the same procedure

used to open a query
that is stored in the access database that is used to

open a table.

Any help would be greatly appreciated.
Thanks
Vince


Dim cn As ADODB.Connection, rs As ADODB.Recordset, r As

Long, c As Long
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.Oledb.4.0; " & _
"Data Source=C:\Access Data\DoctorBlades.mdb;"

Set rs = New ADODB.Recordset

With rs
.Open "tblDoctorBlades", cn, adOpenDynamic,

adLockOptimistic
End With

.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 593
Default Problem with the following code

"Vince" wrote ...

Can anyone tell me what may be wrong with the following code?
It generates an error when it tries to execute the .Open for the recordset.

Dim cn As ADODB.Connection, rs As ADODB.Recordset, r As Long, c As Long
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.Oledb.4.0; " & _
"Data Source=C:\Access Data\DoctorBlades.mdb;"

Set rs = New ADODB.Recordset

With rs
.Open "tblDoctorBlades", cn, adOpenDynamic, adLockOptimistic
End With


Your code works for me. What error are you getting?

Jamie.

--
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
Code problem puiuluipui Excel Discussion (Misc queries) 3 July 3rd 09 07:27 PM
Little problem with this code... simonsmith Excel Discussion (Misc queries) 11 May 21st 06 04:02 AM
VBA code problem excelnoob[_2_] Excel Programming 1 July 5th 04 01:31 PM
Code Problem Todd Huttenstine Excel Programming 3 April 16th 04 09:25 PM
problem with code gareth Excel Programming 1 December 5th 03 03:24 PM


All times are GMT +1. The time now is 07:57 AM.

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

About Us

"It's about Microsoft Excel"