PC Review


Reply
Thread Tools Rate Thread

ADO - Access to Excel

 
 
Philosophaie
Guest
Posts: n/a
 
      13th Mar 2010
Trying to use ADO to move some data to Excel
Excel shows an error when:
Dim Connection As ADODB.Connection is executed.

This is the program:

Sub AccessToExcel()
Dim DBFullName As String
Dim Cnct As String, Src As String
Dim Connection As ADODB.Connection
Dim Recordset As ADODB.Recordset
Dim Col As Integer
Cells.Clear
' Database information
DBFullName = "E:\db.accdb"
' Open the connection
Set Connection = New ADODB.Connection
Cnct = "Provider=Microsoft.ACE.OLEDB.12.0;"
Cnct = Cnct & "Data Source=" & DBFullName & ";"
Connection.Open ConnectionString:=Cnct
'Create RecordSet
Set Recordset = New ADODB.Recordset
With Recordset

Filter
Src = "SELECT * FROM DB1 WHERE DB2 = 'Starting'"
Src = Src & "and Year = '2001'"

..Open Source:=Src, ActiveConnection:=Connection
' Write the field names
For Col = 0 To Recordset.Fields.Count - 1
Range(“A1”).Offset(0, Col).Value = _
Recordset.Fields(Col).Name
Next
'Write the recordset
Range(“A1”).Offset(1, 0).CopyFromRecordset Recordset
End With
Set Recordset = Nothing
Connection.Close
Set Connection = Nothing
End Sub
 
Reply With Quote
 
 
 
 
FSt1
Guest
Posts: n/a
 
      13th Mar 2010
hi
connection may be a reserved word like string.
set string as string????
try this
Dim Con as ADODB Connection 'no dot
also
dim rs as ADODB Recordset 'again no dot
also
Dim col as long

edit the rest of your code to reflect above.
everything else "looked" ok BUT i didn't not test.

Regards
FSt1

regards
FSt1


"Philosophaie" wrote:

> Trying to use ADO to move some data to Excel
> Excel shows an error when:
> Dim Connection As ADODB.Connection is executed.
>
> This is the program:
>
> Sub AccessToExcel()
> Dim DBFullName As String
> Dim Cnct As String, Src As String
> Dim Connection As ADODB.Connection
> Dim Recordset As ADODB.Recordset
> Dim Col As Integer
> Cells.Clear
> ' Database information
> DBFullName = "E:\db.accdb"
> ' Open the connection
> Set Connection = New ADODB.Connection
> Cnct = "Provider=Microsoft.ACE.OLEDB.12.0;"
> Cnct = Cnct & "Data Source=" & DBFullName & ";"
> Connection.Open ConnectionString:=Cnct
> 'Create RecordSet
> Set Recordset = New ADODB.Recordset
> With Recordset
>
> Filter
> Src = "SELECT * FROM DB1 WHERE DB2 = 'Starting'"
> Src = Src & "and Year = '2001'"
>
> .Open Source:=Src, ActiveConnection:=Connection
> ' Write the field names
> For Col = 0 To Recordset.Fields.Count - 1
> Range(“A1”).Offset(0, Col).Value = _
> Recordset.Fields(Col).Name
> Next
> 'Write the recordset
> Range(“A1”).Offset(1, 0).CopyFromRecordset Recordset
> End With
> Set Recordset = Nothing
> Connection.Close
> Set Connection = Nothing
> End Sub

 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      13th Mar 2010
Have you set a reference to the Microsoft ActiveX Data Objects Library?

--

HTH

Bob

"Philosophaie" <(E-Mail Removed)> wrote in message
news:9B33D52F-C520-4976-B1BE-(E-Mail Removed)...
> Trying to use ADO to move some data to Excel
> Excel shows an error when:
> Dim Connection As ADODB.Connection is executed.
>
> This is the program:
>
> Sub AccessToExcel()
> Dim DBFullName As String
> Dim Cnct As String, Src As String
> Dim Connection As ADODB.Connection
> Dim Recordset As ADODB.Recordset
> Dim Col As Integer
> Cells.Clear
> ' Database information
> DBFullName = "E:\db.accdb"
> ' Open the connection
> Set Connection = New ADODB.Connection
> Cnct = "Provider=Microsoft.ACE.OLEDB.12.0;"
> Cnct = Cnct & "Data Source=" & DBFullName & ";"
> Connection.Open ConnectionString:=Cnct
> 'Create RecordSet
> Set Recordset = New ADODB.Recordset
> With Recordset
>
> Filter
> Src = "SELECT * FROM DB1 WHERE DB2 = 'Starting'"
> Src = Src & "and Year = '2001'"
>
> .Open Source:=Src, ActiveConnection:=Connection
> ' Write the field names
> For Col = 0 To Recordset.Fields.Count - 1
> Range("A1").Offset(0, Col).Value = _
> Recordset.Fields(Col).Name
> Next
> 'Write the recordset
> Range("A1").Offset(1, 0).CopyFromRecordset Recordset
> End With
> Set Recordset = Nothing
> Connection.Close
> Set Connection = Nothing
> End Sub



 
Reply With Quote
 
Philosophaie
Guest
Posts: n/a
 
      13th Mar 2010
Dim Con as ADODB Connection
with a space or without a space gives me an error and:

Dim Con as ADODB.Connection
is not working also.
 
Reply With Quote
 
Philosophaie
Guest
Posts: n/a
 
      13th Mar 2010
I put in Tools>References

Added:
Microsoft Access 12.0 Object Library
Microsoft ActiveX Data Objects(Multi-dimensional) 6.0 Library

there are others but they conflict with each other. With these additions it
still does not work.


"Bob Phillips" wrote:

> Have you set a reference to the Microsoft ActiveX Data Objects Library?


 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      13th Mar 2010
Not the Multi-dimensional library, that is for OLAP cubes. You want
Microsoft ActiveX Data Objects 2.n Library as I stated.

--

HTH

Bob

"Philosophaie" <(E-Mail Removed)> wrote in message
news:7FB2ED89-85C9-45EF-A7F8-(E-Mail Removed)...
>I put in Tools>References
>
> Added:
> Microsoft Access 12.0 Object Library
> Microsoft ActiveX Data Objects(Multi-dimensional) 6.0 Library
>
> there are others but they conflict with each other. With these additions
> it
> still does not work.
>
>
> "Bob Phillips" wrote:
>
>> Have you set a reference to the Microsoft ActiveX Data Objects Library?

>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel To Access: Transfer multiple rows from excel to access sam Microsoft Excel Programming 0 20th Jan 2010 09:51 PM
Access Speakers wanted - 2007 Access / Excel User Conferences Damon Longworth Microsoft Access 1 21st Aug 2006 05:01 AM
export access to excel. change access & update excel at same time =?Utf-8?B?ZmFzdGNhcg==?= Microsoft Excel Misc 0 24th Jun 2005 09:27 PM
Closing Excel files from Access and/or quitting Excel from Access Beverly Microsoft Access VBA Modules 1 11th Oct 2003 06:49 PM
Importing excel into access - want access to update data supplied from excel Deborah Microsoft Access External Data 1 30th Jul 2003 01:21 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:39 AM.