oReport:ToExcel() with ADO produces this error:
Either BOF or EOF is True, or the current record has been deleted Requested operation requires a current record. (0x800A0BCD) ADODB.Field
Stack Calls
===========
Called from: => TOLEAUTO:VALUE( 0 )
Called from: errorado.prg => (b)TEST_REPORT( 94 )
Called from: .\source\classes\REPORT.PRG => TREPORT:TOEXCEL( 2150 )
Called from: errorado.prg => (b)TEST_REPORT( 77 )
Called from: .\source\classes\WINDOW.PRG => TWINDOW:KEYDOWN( 2623 )
Called from: .\source\classes\CONTROL.PRG => TMETAFILE:KEYDOWN( 1043 )
Called from: => TWINDOW:HANDLEEVENT( 0 )
Called from: .\source\classes\CONTROL.PRG => TMETAFILE:HANDLEEVENT( 1729 )
Called from: .\source\classes\WINDOW.PRG => _FWH( 3180 )
Called from: => WINRUN( 0 )
Called from: .\source\classes\WINDOW.PRG => TWINDOW:ACTIVATE( 993 )
Called from: .\source\classes\RPREVIEW.PRG => TPREVIEW:ACTIVATE( 162 )
Called from: .\source\classes\RPREVIEW.PRG => RPREVIEW( 1638 )
Called from: .\source\classes\REPORT.PRG => (b)TREPORT_NEW( 187 )
Called from: .\source\classes\REPORT.PRG => TREPORT:ACTIVATE( 883 )
Called from: errorado.prg => TEST_REPORT( 121 )
Called from: errorado.prg => MAIN( 33 )
This is a working simple:
- Code: Select all Expand view
- #include "FiveWin.ch"
#include "report.ch"
#include "inkey.ch"
#include "xbrowse.ch"
#include "hbcompat.ch" // required
REQUEST DBFCDX
static cMdb := "tutor01.mdb"
static oCn
Function main()
SET DELETED ON
SET DATE ITALIAN
SET CENTURY ON
XbrNumFormat( 'A', .t. )
ferase( cmdb )
if .not. File( cMdb )
FW_CreateMDB( cMdb )
endif
CreateTable()
CopyFromDBF()
test_report()
oCn:Close()
QUIT
return nil
function test_report()
LOCAL oFont1, oFont2
LOCAL oReport
LOCAL oRs
LOCAL nHasta := 0, nLinea := 1
oRs := FW_OpenRecordSet( oCn, "CUSTSMAL" )
nHasta := oRs:RecordCount()
oRs:MoveFirst()
DEFINE FONT oFont1 NAME "ARIAL" SIZE 0,-10
DEFINE FONT oFont2 NAME "ARIAL" SIZE 0,-10 BOLD
SetKey(VK_F2, { || oReport:ToExcel() })
REPORT oReport TITLE "*** Mi Primer Reporte con tílde ***" ;
FONT oFont1, oFont2 ;
PREVIEW CAPTION "Mensaje del título - press F2 to export to Excel - "+FWVERSION
//oReport:bInit := { || oRs:MoveFirst() }
COLUMN TITLE "ID" DATA oRs:Fields("ID"):Value PICTURE "9999"
COLUMN TITLE "NAME:" DATA oRs:Fields("CUSTNAME"):Value SIZE 30
COLUMN TITLE "MARRIED:" DATA oRs:Fields("MARRIED"):Value
COLUMN TITLE "SALARY: " DATA oRs:Fields("SALARY"):Value ;
TOTAL ;
RIGHT ;
PICTURE "9,999,999"
END REPORT
IF oReport:lCreated
oReport:bSkip := { || (nLinea++, oRs:MoveNext())}
ENDIF
ACTIVATE REPORT oReport ;
WHILE nLinea <= nHasta
oFont1:End()
oFont2:End()
?"END"
oRs:Close()
RETURN NIL
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
static function CreateTable()
local cSql, c
oCn := FW_OpenAdoConnection( cMdb )
TRY
oCn:Execute( "DROP TABLE CUSTSMAL" )
CATCH
END
TEXT INTO cSql
CREATE TABLE CUSTSMAL (
ID AUTOINCREMENT PRIMARY KEY,
CUSTNAME VARCHAR( 30 ),
MARRIED BIT,
AGE BYTE,
SALARY MONEY
)
ENDTEXT
oCn:Execute( cSql )
return nil
//----------------------------------------------------------------------------//
static function CopyFromDBF()
local oRs
oRs := FW_OpenRecordSet( oCn, "CUSTSMAL" )
USE CUSTOMER NEW ALIAS CUST SHARED READONLY VIA 'DBFCDX'
do while ! eof() .and. RecNo() < 6
oRs:AddNew( { "CUSTNAME", "MARRIED", "AGE", "SALARY" }, ;
{ Left( Trim( CUST->FIRST ) + ' ' + Trim( CUST->LAST ), 30 ), ;
CUST->MARRIED, CUST->AGE, CUST->SALARY } )
SKIP
enddo
CLOSE CUST
oRs:Close()
return nil
Thank you. Best regards
CUSTOMER is SAMPLES\CUSTOMER