Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using PCancel to test whether data has been found before Exporting

Status
Not open for further replies.
Jan 8, 2001
163
US
Hello. I've created a program that grabs each id field from a table and then for each id that it grabs, it runs a calls the rdc for a certain report and then exports the report automatically in both Word and Excel format with dynamically set names. The trouble is that I don't want the program to export a report if there is no data reported. ie/ if that id parameter has no data to report. I'm trying to use Seagate's "pCancel" option to do this. It's new to CR8 and it seems relatively simple when dealing with a viewer. However, I can't figure out when pCancel is returned when exporting a report. I'm including my code below. If anyone could help me I would appreciate it very much.


‘---- RETURNS PCANCEL AS TRUE WHEN NO DATA FOUND IN RDC ----
‘---- pCancel HAS ALSO BEEN DECLARED A GLOBAL VARIABLE -----
Private Sub Report_NoData(pCancel As Boolean)
pCancel = True
End Sub


'-- GENERATES AND SAVES ALL PUBLISHER REPORTS FROM FORM 1--
Private Sub cmdGenPUBRrpts_Click()

Dim strSelPubr As String ‘Selection string
Dim strFilename1x As String 'Report name for Excel File
Dim strFilename1w As String 'Report name for Word RTF File

strSelPubr = "Select a.id from log.r_pubr_rpt_log a "
strSelPubr = strSelPubr & "where a.datestamp = to_date('" & strPbrCrystalDate & "','YYYY,MM,DD')"

With adoRecordsetName1 'Declared way at the top of the form
.ActiveConnection = adoConn
.CursorType = adOpenDynamic
.Open strSelPubr
.MoveFirst
End With

Do Until adoRecordsetName1.EOF 'HERE'S WHERE THE LOOP STARTS

Dim strPubrID As String
Dim Report1 As New crptPBR_DS_UR


'GETS THE CURRENT ID FROM THE RECORDSET
strPubrID = adoRecordsetName1(0).Value

'SETS THE FILE NAMES FOR THE REPORTS TO BE EXPORTED
strFilename1x = "C:/My Documents/Publisher Reports/" & strPubrID & "_" & strPubrLogMonth & "1.xls"
strFilename1w = "C:/My Documents/Publisher Reports/" & strPubrID & "_" & strPubrLogMonth & "1.doc"

'SETS THE SELECTION STRING TO BE USED IN REPORT
strSelectionA = " {M_PUBLISHER.ID} = " & strPubrID & _
" And {R_PUBN_RPT_LOG.DATESTAMP} = DATE ('" & strPbrCrystalDate & "')"
'LOG ON DATABASE
Report1.Database.Tables(1).SetLogOnInfo "DT", "DT", "u", "p"

'SET SELECTION FORMULA WITH STRING SET ABOVE
Report1.RecordSelectionFormula = strSelectionA

If pCancel = False Then
With Report1
.ExportOptions.DestinationType = crEDTDiskFile
.ExportOptions.FormatType = crEFTExcel80
.ExportOptions.DiskFileName = strFilename1x
.Export (False)
.ExportOptions.DestinationType = crEDTDiskFile
.ExportOptions.FormatType = crEFTRichText
.ExportOptions.DiskFileName = strFilename1w
.Export (False)
End With
Else
pCancel = False
End If


pCancel = False
adoRecordsetName1.MoveNext
Loop
End Sub

Thanks Again,
CrystalVisualBOracle :-V
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top