Bob Barnes said:
Dirk - Hope you return to read this. I've also posted this
in "excel.programming" this AM.
Also searched the MS KB for "The server threw an exception" - nothing
as such
in Access 2000, but a Win2K Patch was mentioned.
Is there a good alternative to "CopyFromRecordset"?
When I need a single value, I use an Access Recordset,
& write that value (no problems), but this is a Recordset
of up to 52 records with 2 fields per Record...certainly not big.
Parts of my code...
Set RS = CurrentDb.OpenRecordset(strSql, dbOpenSnapshot) <== No
problem w/ the "strSQL" 'start Excel
Set objXLApp = CreateObject("Excel.Application")
...................
'select desired worksheet
Set objXLSheet = objXLWb.Worksheets(strWorkSheet) <== No problem w/
the "strWorkSheet" objXLSheet.Range(strCellRef).Clear 'Is "TheData"
<== No problem w/ the "strCellRef"
objXLSheet.Range(strCellRef).CopyFromRecordset RS <=== Fails there
w/ "...exception" above.
Funny thing...I've been using this code for a couple of months w/ no
problems.
Maybe a Server problem here ??
ANY insight welcomed. TIA - Bob
I don't have much to offer. It could be a problem with the server or
the installation of DAO or Jet, especially if this exact routine in this
same database was working before and has suddenly stopped. I would
certainly investigate problems with the recordset or the call to
CopyFromRecordset first, though. You might try:
(a) Verifying (by inspection in the Locals Window) that the recordset is
open and not at EOF when it is passed to the CopyFromRecordset method.
(b) Opening a dynaset-type recordset instead of a snapshot --
dbOpenDynaset instead of dbOpenSnapshot.
(c) Specifying the number of rows to copy, in the call to
CopyFromRecordset. I seem to recall this being an issue the one time in
the past that I used this method, but that's all hazy now. I *think*
that if you specify more rows than the recordset actually contains, it's
still okay. However, if you open the recordset as a dynaset you can do
RS.MoveLast, Rs.MoveFirst, and then pass RS.RecordCount to the
CopyFromRecordset method as the number of rows.