dbTalk Databases Forums  

Unusual .CopyFromRecordset behavior in A2K7

comp.databases.ms-access comp.databases.ms-access


Discuss Unusual .CopyFromRecordset behavior in A2K7 in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
James A. Fortune
 
Posts: n/a

Default Unusual .CopyFromRecordset behavior in A2K7 - 09-11-2011 , 10:38 PM






I'm not sure if I found a bug or a feature in A2K7 :-). I have code
that exports a query to Excel. The code looks something like:

With ExcelSheet.Application
Set MyRS = MyDB.OpenRecordset(strSQL, dbOpenSnapshot)
.Cells(1, 1) = "CNC Machine"
.Cells(1, 2) = "Avg. Run-Time Percentage"
strRange = "A2"
strSQL = "qryRunningPercentYTD"
Set MyRS = MyDB.OpenRecordset(strSQL, dbOpenSnapshot)
'MyRS.MoveLast
.Range(strRange.CopyFromRecordset MyRS
DoEvents
Call MilliSleep(1000)
MyRS.Close
Set MyRS = Nothing
...

That code works well. When I uncomment the MyRS.MoveLast line, only
the last record gets exported to the spreadsheet. The help file
suggests that the entire recordset should get transferred, but it
doesn't. Note: I didn't try the export after moving to a random
record in the recordset.

James A. Fortune
CDMAPoster (AT) FortuneJames (DOT) com

Reply With Quote
  #2  
Old   
Douglas J Steele
 
Posts: n/a

Default Re: Unusual .CopyFromRecordset behavior in A2K7 - 09-12-2011 , 04:15 PM






I don't have Office 2007 installed on this machine, so I can't check, but in
Excel 2010, the Help file entry on CopyFromRecordset explicitly states
"Copying begins at the current row of the Recordset object."

Of course, the snippet you've pasted is invalid code: you've got an opening
parenthesis after the .Range, but no closing one.


"James A. Fortune" wrote in message
news:320b6fc1-c19f-4d9e-868a-cfdfc485bde0 (AT) o15g2000vbe (DOT) googlegroups.com...

I'm not sure if I found a bug or a feature in A2K7 :-). I have code
that exports a query to Excel. The code looks something like:

With ExcelSheet.Application
Set MyRS = MyDB.OpenRecordset(strSQL, dbOpenSnapshot)
.Cells(1, 1) = "CNC Machine"
.Cells(1, 2) = "Avg. Run-Time Percentage"
strRange = "A2"
strSQL = "qryRunningPercentYTD"
Set MyRS = MyDB.OpenRecordset(strSQL, dbOpenSnapshot)
'MyRS.MoveLast
.Range(strRange.CopyFromRecordset MyRS
DoEvents
Call MilliSleep(1000)
MyRS.Close
Set MyRS = Nothing
...

That code works well. When I uncomment the MyRS.MoveLast line, only
the last record gets exported to the spreadsheet. The help file
suggests that the entire recordset should get transferred, but it
doesn't. Note: I didn't try the export after moving to a random
record in the recordset.

James A. Fortune
CDMAPoster (AT) FortuneJames (DOT) com

Reply With Quote
  #3  
Old   
James A. Fortune
 
Posts: n/a

Default Re: Unusual .CopyFromRecordset behavior in A2K7 - 09-13-2011 , 07:57 AM



On Sep 12, 5:15*pm, "Douglas J Steele"
<NOSPAM_djsteele (AT) NOSPAM_gmail (DOT) com> wrote:
Quote:
I don't have Office 2007 installed on this machine, so I can't check, butin
Excel 2010, the Help file entry on CopyFromRecordset explicitly states
"Copying begins at the current row of the Recordset object."
It might be in the A2K7 help file also :-). I'll check the next time
I open A2K7.

Quote:
Of course, the snippet you've pasted is invalid code: you've got an opening
parenthesis after the .Range, but no closing one.
Well parsed. I think it should be:

..Range(strRange)
..CopyFromRecordset MyRS

BTW, I see that you and Arvin wrote an Access book.

Thanks,

James A. Fortune
CDMAPoster (AT) FortuneJames (DOT) com

Reply With Quote
Reply




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.