Wrox Programmer Forums
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 28th, 2006, 10:05 AM
Registered User
 
Join Date: Sep 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default ADO excel2Excel....

:)Hi all,
I have a (probably very trivial) problem...I would like to ventilate data stored in a "bulk data" workbook to diverse final users workbooks using ADO and steering the whole process from another workbook. Opening and reading the first data set is no problem, but how do I download to the target workbooks? (ie how does one use the method .CopyFromRecordSet to an non opened data workbook?)

Code:
Sub StatIntRead()
 
Dim objConnect As ADODB.Connection
Dim szConnect As String
Dim szSQL As String
Dim myWkb As String
Dim rsData As ADODB.Recordset
Dim myUsr As String

 myWkb = "Z:\Working\bulk.xls"
 
'Create connection chain
szConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
            "Data Source=" & myWkb & ";" & _
            "Extended Properties=Excel 8.0;"

myUsr="AAA" 'will loop on users

szSQL = "SELECT * FROM [Sheet1$A4:W65000] WHERE Usr = " & myUsr

Set rsData = New ADODB.Recordset
rsData.Open szSQL, szConnect, adOpenForwardOnly, adLockReadOnly, adCmdText

If Not rsData.EOF Then
' Feuil4.Range("a2").CopyFromRecordset rsData  '<= this work OK
'  but outputs in the active, open workbook
' I want to output in workbook AAA.xls
'
' If myUsr='AAA' Then ???? create a new connection?
'  
Else
End If

'Clear up RecordSet
rsData.Close
Set rsData = Nothing

End Sub






Similar Threads
Thread Thread Starter Forum Replies Last Post
ADO??? monabaumgartel BOOK: Beginning Access 2003 VBA 1 August 7th, 2007 05:44 PM
Difference between ADO and ADO.NET rakeshclose2u ADO.NET 2 April 23rd, 2007 03:57 AM
ADO AND ADO.NET royalsurej ADO.NET 1 November 8th, 2004 08:28 AM
ADO could ADO counot find the specified provider. Rob Collie Classic ASP Databases 2 June 9th, 2003 04:12 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.