Passing Dates/Date Ranges in Visual Basic using the Crystal Report Engine API Calls

You may want to pass date or date range information from your Visual Basic application to the Crystal Report Engine for use in formulas, selection formulas, etc. Here is an example showing a way to do it successfully:

  1. Start by opening a print job and assigning the print job handle to a variable.
JobHandle% = PEOpenPrintJob ("C:\CRW\CUSTOMER.RPT")
  1. Create variables that hold the year, month, and day for both the start and end of the range.
StartYear$ = 1992
StartMonth$ = 01
StartDay$ = 01
EndYear$ = 1993
EndMonth$ = 12
EndDay$ = 31
  1. Now build a string to pass to the record selection formula. This is done in two steps:
StrtSelect$ = "{filea.STARTDATE} < Date 
(" + StartYear$ + ", " + StartMonth$ + ", "
+ StartDay$ +")" EndSelect$ = "{filea.ENDDATE} < Date
(" + EndYear$ + ", " + EndMonth$ +
", " + EndDay$ +")"

Recselct$ = StrtSelect$ + " AND " + EndSelect$

  1. Once your formula is built, set the record selection formula for the report.
RetCode% = PESetSelectionFormula 
(JobHandle%, RecSelect$)
  1. Finally, print the report.
RetCode% = PEStartPrintJob (JobHandle, 1)
RetCode% = PEClosePrintJob (JobHandle, 1)
  1. Modify this code to fit your needs.


Seagate Software IMG Holdings, Inc.
http://www.seagatesoftware.com
Support services:
http://support.seagatesoftware.com