Nota: Articoli etichettati come Snippet non contengono codice completo ma solo parti di esso, recuperate da appunti. Per cui, potrebbe essere necessario modificarne alcuni nomi o indici. Per ogni chiarimento, lasciate un commento all’articolo.
Per visualizzare le query esatte che un report .rpt (creato in Crystal Reports) e tutti i suoi sottoreport generano sul database è sufficiente utilizzare all’interno dell’applicazione (Visual Basic 6, nello specifico), il seguente codice.
Nota: questo snippet è utile qualora non si disponga dell’accesso ai log del DBMS o esso non li generi (es: DB Access).
Private Sub cmdAnteprimaLibretto_Click()
Dim crAPP As CRAXDRT.Application
Dim myReport As CRAXDRT.Report
On Error GoTo err_cmdAnteprimaLibretto_Click
Set crAPP = New CRAXDRT.Application
Set myReport = crAPP.OpenReport(gen.rptLibretto)
myReport.DiscardSavedData
myReport.FormulaSyntax = 0
myReport.RecordSelectionFormula = “{0Frontespizio.Matricola} = ‘” + gen.personaAttiva.Matricola
myReport.ParameterFields.GetItemByName(“versioneApp”).AddCurrentValue gen.versioneApp
‘STAMPA DELLA QUERY PRINCIPALE <<<<<<<<
Debug.Print myReport.SQLQueryString
Dim crxSections As CRAXDRT.Sections
Dim crxSection As CRAXDRT.Section
Dim CRXReportObject As Object
Dim crxSubreportObject As SubreportObject
Dim crxSubreport As CRAXDRT.Report
Set crxSections = myReport.Sections
For Each crxSection In crxSections
For Each CRXReportObject In crxSection.ReportObjects
If CRXReportObject.Kind = crSubreportObject Then
Set crxSubreportObject = CRXReportObject
Set crxSubreport = crxSubreportObject.OpenSubreport
‘STAMPA DELLA SOTTOQUERY <<<<<<<<
Debug.Print crxSubreport.SQLQueryString
Set crxSubreport = Nothing
End If
Next
NextSet myReport = Nothing
Set crAPP = Nothing
Exit Suberr_cmdAnteprimaLibretto_Click:
errDescr = Err.Description
Set myReport = Nothing
Set crAPP = Nothing
MsgBox “Problemi durante la visualizzazione del documento” + vbCrLf + errDescr, vbCritical, gen.titolo
End Sub