Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default copyFromRecordSet code in excel-vba

I need to copy the result of a query from Access to Excel in a particular wks.

I haven't been able to declare "db" as a database and I get a prompt saying
that user type not defined.

I copied the code from a previous thread from 2005 that was like this:

Dim DBFullName As String
Dim TableName As String
Dim FieldName As String
Dim TargetRange As Range
Dim db As dataBase
Dim rs As Recordset
Dim intColIndex As Integer

DBFullName = "C:\Documents and Settings\Junior\My Documents\Consumer "
Loans.mdb " "
TableName = "tbl_CLC"

Set TargetRange = Excel.Application.Worksheets("CLC").Range("A1")
Set db = OpenDatabase(DBFullName)
Set rs = db.OpenRecordset(TableName, dbOpenTable) ' all records
For intColIndex = 0 To rs.Fields.Count - 1
TargetRange.Offset(0, intColIndex).Value = _
rs.Fields(intColIndex).Name
Next
' write recordset
TargetRange.Offset(1, 0).CopyFromRecordset rs
Set rs = Nothing
db.Close
Set db = Nothing

Any suggestions on how to proceed?

Thank you in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default copyFromRecordSet code in excel-vba

http://www.erlandsendata.no/english/...php?t=envbadac

--
---------------------------
Mauro Gamberini
http://www.riolab.org/

"oscar.c.marin" ha scritto nel
messaggio ...
I need to copy the result of a query from Access to Excel in a particular
wks.

I haven't been able to declare "db" as a database and I get a prompt
saying
that user type not defined.

I copied the code from a previous thread from 2005 that was like this:

Dim DBFullName As String
Dim TableName As String
Dim FieldName As String
Dim TargetRange As Range
Dim db As dataBase
Dim rs As Recordset
Dim intColIndex As Integer

DBFullName = "C:\Documents and Settings\Junior\My Documents\Consumer "
Loans.mdb " "
TableName = "tbl_CLC"

Set TargetRange = Excel.Application.Worksheets("CLC").Range("A1")
Set db = OpenDatabase(DBFullName)
Set rs = db.OpenRecordset(TableName, dbOpenTable) ' all records
For intColIndex = 0 To rs.Fields.Count - 1
TargetRange.Offset(0, intColIndex).Value = _
rs.Fields(intColIndex).Name
Next
' write recordset
TargetRange.Offset(1, 0).CopyFromRecordset rs
Set rs = Nothing
db.Close
Set db = Nothing

Any suggestions on how to proceed?

Thank you in advance.



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
Is CopyFromRecordset a bug of Excel? [email protected] Excel Programming 2 October 31st 09 05:53 AM
Format data in Excel after using copyfromrecordset jj Excel Discussion (Misc queries) 2 June 13th 07 06:48 AM
MFC - CopyFromRecordset - Copy data to Excel Jen Leonard Excel Programming 0 June 7th 06 03:01 AM
Excel VBA - CopyFromRecordset (ADO) Problems with 107000 records Philip Excel Programming 8 March 24th 05 08:53 AM
Excel 2003 - 'CopyFromRecordset' Error Chris Wiley Excel Programming 2 October 2nd 04 05:42 AM


All times are GMT +1. The time now is 06:32 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"