Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Cannot use recordset twice with copy From recordset

Here is the snippet of code (some lines have been left out):

Dim conn As New ADODB.Connection
rs05.Open "SELECT * FROM [05 Store Count Summary]", conn, adOpenDynamic
Dim xlApp As New Excel.Application
With xlApp
.Visible = False
.Workbooks.Open xlPath & xlBkNamePRINT
Set xlBkPRINT = .ActiveWorkbook
.Workbooks.Open xlPath & xlBkNameQTD
Set xlBkQTD = .ActiveWorkbook
.Workbooks.Open xlPath & xlBkNameWK
Set xlBkWK = .ActiveWorkbook
End With

'Part A
xlBkWK.Activate
xlBkWK.Worksheets("Environmental Step 3").Activate
xlApp.Range("C5").CopyFromRecordset rs05

'Part B
xlBkQTD.Activate
xlBkQTD.Worksheets("Environmental Step 3").Activate
xlApp.Range("C5").CopyFromRecordset rs05

I have one recordset that is being pasted into two seperate worksheets. From
stepping through the code, Part A is being executed, but not Part B. There is
no error thrown, the workbook is activated, it goes to the respective tab,
but then nothing is pasted. When I rearrange Part A with Part B (Part B is
executed first), the code works for Part B but not A. This code was working
in the past, but something over the past year broke it. There is no error
being thrown. Thanks in advance for any insight into this issue.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Cannot use recordset twice with copy From recordset


try adding

RS05.MoveFirst


I'm not sure why the code ever worked. Not sure if you are opening and
closing the recordset. A recordset is similar to a file which moves the
pointer as it move the data so when you done reading everything the
point is at the end of the file and you have to reset the pointer to the
beginning of the file before you can read the data a 2nd time.


--
joel
------------------------------------------------------------------------
joel's Profile: 229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=176179

Microsoft Office Help

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
Copy from recordset errors in ADO Spike Excel Programming 8 March 10th 07 10:12 PM
Copy an array into an ADO recordset? quartz[_2_] Excel Programming 3 January 4th 06 08:10 AM
Copy From Recordset Nath Excel Programming 0 July 13th 04 12:30 PM
Type recordset/recordset? FlaviusFlav[_9_] Excel Programming 4 May 24th 04 12:16 PM
Copy Recordset into array? Andrew_blue Excel Programming 2 May 6th 04 07:23 PM


All times are GMT +1. The time now is 01:37 AM.

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"