I've restored the main alias and also the pointer just after the report was called the first time (preview). This works. I would appreciate it if you can look at he code still, just to make sure I am doing it correct. I'm also interested how your RS preview works. I would prefer doing it the correct way.
Here is my code:
*!* Initialize event
LOCAL cRSServerFolder, cGdiPlusX
cRSServerFolder = 'n:\bkb\RsDev'
DO (ADDBS(cRSServerFolder) +'ReportSculptor.App')
cGdiPlusX=addbs(_oRSGO.RS_Root) + 'GdiPlusX\system.app'
do (cGdiPlusX)
set classlib to "C:\Program Files\Microsoft Visual FoxPro 9\Ffc\_ReportListener.VCX" additive
*!* Print command button
IF ISBLANK(thisform.txtDeclREF.value) then
WAIT WINDOW 'You have TO enter a REFERENCE TO be used on printout!' timeout 2
thisform.txtDeclREF.SetFocus
RETURN
ELSE
lcRef = thisform.txtDeclREF.value
ENDIF
SELECT lotcurs
COUNT TO lnRecCnt
IF lnRecCnt > 0 then
REPORT FORM declletter TO PRINTER PROMPT preview
thisform.cmdEmail.Enabled = .T.
SELECT lotcurs
GOTO top
IF thisform.chkEmailVet.Value = 1 then
lnAnswer = MESSAGEBOX('Are you sure you want to email the State VET?',4+32+256,'Email confirmation')
IF lnAnswer = 6 then
WAIT WINDOW 'Preparing email...' TIMEOUT 3
LOCAL cRSServerFolder, cGdiPlusX
cRSServerFolder = 'n:\bkb\RsDev'
DO (ADDBS(cRSServerFolder) +'ReportSculptor.App')
cGdiPlusX=addbs(_oRSGO.RS_Root) + 'GdiPlusX\system.app'
do (cGdiPlusX)
set classlib to addbs(home()) + "FFC\" + "_ReportListener.VCX" additive
gcBuyer = thisform.cbuyer
IF ISBLANK(thisform.txtDeclREF.value) then
WAIT WINDOW 'You have TO enter a REFERENCE TO be used on printout!' timeout 2
thisform.txtDeclREF.SetFocus
RETURN
ELSE
lcRef = thisform.txtDeclREF.value
ENDIF
cFrx= 'declletter.frx'
=frx2rs(cFrx, 5 , .F.)
thisform.sendemail()
lcfrom = 'w:\send\' + ALLTRIM(gcExpFile) + '.pdf'
lcTo = 'w:\send\Talman reports\RVF\Emails send\' + ALLTRIM(gcExpFile) + '.pdf'
COPY FILE (lcfrom) TO (lcTo)
DELETE FILE (lcFrom)
ELSE
WAIT WINDOW 'Email cancelled on users request!' TIMEOUT 2
ENDIF
ENDIF
ELSE
WAIT WINDOW 'You have to list the records before printing them!' TIMEOUT 2
ENDIF
*!* RS program
function rsGlobalObjectSetup
lcExt = TTOC(DATETIME(),1)
gcExpFile = ALLTRIM(gcBuyer) + 'RVFdecl' + ALLTRIM(lcExt)
with _oRSGO
.xfrx_active = 'Y'
.xfrx_path = '\XFRX127'
.rs_EngineClass = 'MyRS'
.LanguagesEnabled=.f.
.myLanguage = 'English'
.rsExportFolder = 'W:\send'
.rsExportStem=(gcExpFile)
endwith
function pic4rs
lparameters cFile
local lcTmpPic,cBmpAsStr
lcTmpPic=addbs(getenv('temp')) + sys(2015) + '.' + justext(cFile)
cBmpAsStr = filetostr(cFile)
=strtofile( cBmpAsStr , lcTmpPic )
return lcTmpPic
function RsFrx
lparameters cFrxFile,cForClause,cWhileClause,cScope,cSummary
if type('cFrxFile') <> 'C'
return .f.
endif
if vartype(cForClause) <> 'C' or len(alltrim(cForClause)) = 0
cForClause = '.t.'
endif
if vartype(cWhileClause) <> 'C' or len(alltrim(cWhileClause)) = 0
cWhileClause = '.t.'
endif
local loReportListener,oRptStream
oRptStream = createobject('Frx2RsConverter')
loReportListener = createobject("RsFrxReader")
loReportListener.oRSRead = oRptStream
report form (cFrxFile) for &cForClause while &cWhileClause object loReportListener
loReportListener.release
loReportListener=null
return oRptStream
define class MyRS as rsEngine
lAutoPageHeader=.t.
lAutoPageFooter=.t.
rsPublicsHeader='Report Sculptor Version 0.95 Beta'
rsPublicsFooter='Report Sculptor Version 0.95 Beta'
rsPreviewWindowType=1
procedure WithFile
lparameters cFile
wait wind cFile + Chr(13) + 'Created Sucessfully' timeout 2
procedure EmailOutput
lparameters cFile
#define oleEmailItem 0
local oOutlook,oEmail
oOutlook = createobject('Outlook.Application')
oEmail = oOutlook.CreateItem(oleEmailItem)
oEmail.to = 'admin@report-sculptor.com'
oEmail.CC = ''
oEmail.subject='Report Sculptor - Sample'
oEmail.body='I Love Report Sculptor :) '
oEmail.Attachments.add(cFile)
oEmail.display
procedure my_RsPreview
local cForm
cForm = this.rsPreviewSCX
do form (cForm) with this name oPreviewForm noshow
if this.rsPreviewWindowType > 0
oPreviewForm.windowtype= 1
endif
oPreviewForm.show()
endproc
enddefine
Thanks
Irene