Hai,

Try this one

if DataEnvironement1.rsCommand1.state=1 then DataEnvironment1.rsCommand1.close
endif

datareport1.printreport