*:
*: REPORTS.DFT - a dBFast Template File
*:
*:  Program: <<PROG_NAME>>
*:     Desc: <<DESC>>
*:
*:   Author: <<AUTHOR>>
*: Copyright <<COPYRITE>>
*:

SET PROCEDURE TO <<PROG_NAME>>

#DEFINE csViewClose   'View.Close'
#DEFINE csCaretClose  'CARET.Close'
#DEFINE csReportClose 'Report.Close'

DECLARE PFUNCTION GetModuleHandle RETURNING INTEGER IN DLL kernel

IF GetModuleHandle('CARETRUN.EXE') = 0
  WRUN CARETRUN.EXE
ENDIF

TALK TO CARETRUN ABOUT SYSTEM

nSeconds = SECONDS()
DO WHILE (SECONDS() - nSeconds) < 3
  CHKEVENT()
  IF CONTACT()
    EXIT
  ENDIF
ENDDO

IF .NOT. CONTACT()
  BEEP
  WARNING(csCARETRunErr,csCARETNotRun,384)
  RETURN
ENDIF

<<DO BEFORE>>

*: send the File.Open command with the report name
EXECUTE '[File.Open(<<PROG_NAME>>.RET)]'

// The '[File.Preview]' command will allow the user to preview the report
// to screen before printing.  There is a PRINT button on the preview
// screen that can be used to print the report once the preview is done.
EXECUTE '[File.Preview]'

// Comment out the above command and uncomment this one to only allow
// printing a report and not go directly to preview mode.
// EXECUTE '[File.Print(0,0)]'

CARETEvents = SPACE(20)
IF AUTODATA('CARETEVENTS')
  *: sit in the loop and wait for the report to done
  DO WHILE CARETEvents <> csReportClose .AND. ;
           CARETEvents <> csViewClose   .AND. ;
           CARETEvents <> csCARETClose
    CHKEVENT()
  ENDDO

  IF CARETEvents <> csCARETClose 
    EXECUTE '[File.Exit()]'
  ENDIF  

  STOPDATA('CARETEVENTS')
ELSE
  BEEP
  WARNING(csCARETErr,csCARETNoStatInfo,387)
ENDIF

TERMINATE

<<DO AFTER>>

RETURN
