I am creating a WSH script which uses a rather complex SQL statement. For some reason just with this SQL statement and no other I get the 800A0E78 error - "Operation is not allowed when the object is close" - when I check the status of oRS.State its at 0.I just can't see where I am going wrong as the SQL statement works fine in query analyzer.sSQL = "create table #Quoted ( " &_ " job_id int, " &_ " supplier_id int, " &_ " quoted decimal(10,2), " &_ " po_id int) " &_ "insert into #Quoted " &_ " (job_id,supplier_id,quoted,po_id) " &_ " select job_id, p.supplier_id, sum(cost) as 'quoted' ,po_id " &_ " from tblPurchaseorder p " &_ " where " &_ " job_id in (" &_ " select distinct si.job_id from tblSalesInvoice si, tblEstimate e " &_ " where " &_ " si.est_id=e.est_id " &_ " and si.invoiceDate between GetDate()-60 and GetDate()) " &_ " and (p.dateFullyInvoiced is null or p.dateFullyInvoiced >= GetDate()) " &_ " group by job_id,p.supplier_id,po_id " &_ " create table #Invoiced (" &_ " job_id int, " &_ " supplier_id varchar(20), " &_ " su_code varchar(20), " &_ " invoiced decimal(10,2), " &_ " po_id int) " &_ " insert into #Invoiced " &_ " (job_id,supplier_id,su_code,invoiced,po_id) " &_ " select job_id, supplier_id, su_code, " &_ " sum(case type " &_ " when 'I' then valuenet " &_ " when 'C' then -valuenet " &_ " end) " &_ " as 'invoiced' ,po_id " &_ " from tblPurchaseInvoice " &_ " where job_id in (select distinct si.job_id from tblSalesInvoice si, tblEstimate e " &_ " where " &_ " si.est_id=e.est_id " &_ " and si.invoiceDate between GetDate()-60 and GetDate())" &_ " and po_id in (select po_id from tblPurchaseOrder where " &_ " dateFullyInvoiced is null or dateFullyInvoiced >= GetDate()) " &_ " and invoiceDate between GetDate()-60 and GetDate() " &_ " group by job_id,supplier_id, su_code,po_id " &_ " select q.job_id,Quoted, isnull(invoiced,0) as 'invoiced', " &_ " (Quoted-isnull(invoiced,0)) as 'accrual', " &_ " s.supplier_code, s.supplier_name,e.title " &_ " from #Quoted q " &_ " left outer join #invoiced i " &_ " on (q.job_id=i.job_id AND q.supplier_id=i.supplier_id and q.po_id=i.po_id) " &_ " join tblsupplier s " &_ " on (s.supplier_id=q.supplier_id) " &_ " join tblestimate e " &_ " on (e.job_id=q.job_id) " &_ " where (Quoted-isnull(invoiced,0))<>0 " &_ " order By q.job_id,s.supplier_name " &_ " drop table #Quoted " &_ " drop table #Invoiced " set oRs=CreateObject("ADODB.recordset")mydsn = "********************" oRs.Open sSQL, mydsn, 3, 3 ' adOpenStatic and adLockOptimistic are ideal cursor for a recordcount.wsh.echo oRS.State