stenshin
Messages postés1Date d'inscriptionmardi 14 juin 2005StatutMembreDernière intervention11 juillet 2005
-
11 juil. 2005 à 09:14
arezkiTerkmani
Messages postés2Date d'inscriptiondimanche 21 janvier 2007StatutMembreDernière intervention15 novembre 2010
-
28 mars 2007 à 17:40
Bonjour,
j'effectue un stage dans lequel je dois établir un programme en VB capable de générer des états Crystal Report, de les mettre au format PDF puis de les envoyer par mail à une liste de destinataire.
L'envoi par mail à déja été à peu pres traité, mais je galère avec la première partie: générer des états crystal depuis VB. J'ai trouvé du code sur le site mais il ne fonctionne pas avec la version de Crystal ( la 8) dont je dispose ( je devrais bientôt disposer de la version XI de Crystal, j'espère que ça ira mieux.).
Mais pour l'instant comme il faut que j'avance qqun pourrait-il m'aider?
J'ai déjà essayé les codes proposés il y a qqes mois sur le forum par rykowan , et pleins d'autres .Mais soit les bibilothèques ne sont pas reconnues, soit ba ça ne fait rien ou il y a des erreurs.
Déjà une question: est-il possible via VB6 de générer des états crystal Report ?
Merci de votre aide, j'en ai vraiment besoin :)
stenshin,
gaa179
Messages postés361Date d'inscriptionmercredi 21 mai 2003StatutMembreDernière intervention12 novembre 20092 11 juil. 2005 à 09:50
Salut,
Si tu veux créer un état CR à partir de ton apllic VB, tu rajoutes l'OCx CRDesigner. Il te permet de dessiner ton état au travers d'une interface graphique.
Si tu veux le gérer par code entièrement, tu auras aussi besoin de l'ocx, ainsi que tu code supplémentaire pour gérer les objets à l'intérieur de ton état.
Voici un exemple qui répond au premier cas:
' *************************************************************
' Purpose: Demonstrate how to display a report in the
' Embeddable Crystal Reports Designer Control
' (Embeddable Designer) and preview the report.
' (New to Crystal Reports 8.5)
'
' The Embeddable Designer allows the developer to display
' a fully functional Crystal Reports designer at runtime.
'
' In this sample the Embeddable Designer can be set to
' either a new or existing report. Once the report is
' designed or edited click the 'Preview' tab to display
' the report.
'
Option Explicit
Private Const OpenDialogFilter As String = "Crystal Reports |*.rpt"
Private errString, errTitle As String
Dim m_Application As New CRAXDDRT.Application
Dim m_Report As CRAXDDRT.Report
' *************************************************************
'DisplayReport is a procedure that
' - Enables the Tab control the first time a report is created
' or opened.
' - Sets the report object to the Embeddable Designer(CRDesigner1).
' - Disables the Help menu in the Embeddable Designer.
' - Sets the report object to the Crystal Report Viewer Control
' (CRViewer1).
' - Sets the Crystal Reports Viewer to view the report.
'
Public Sub DisplayReport()
On Error GoTo errhandler
' Enable the tab control if disabled.If SSTab1.Enabled False Then SSTab1.Enabled True
' Set the Report Object
CRDesignerCtrl1.ReportObject = m_Report
' Note----------------
' Set all other properties for CRDesignerCtrl1 after setting the
' ReportObject property
' --------------------
' Disable the Help menu
CRDesignerCtrl1.EnableHelp = False
' Set the report source
CRViewer1.ReportSource = m_Report
' Set the zoom level to fit the page width to the
' viewer window
CRViewer1.Zoom 1
' Set the viewer to view the report
CRViewer1.ViewReport
Exit Sub
errhandler:
errString = "Error # " & CStr(Err.Number) & " " & Err.Description
errTitle = Err.Source
MsgBox errString, vbCritical, errTitle
End Sub
' *************************************************************
Private Sub Form_Load()
'Set the tab control to display the Designer tab
'when the form is loaded
SSTab1.Tab = 0
End Sub
' *************************************************************
Private Sub SSTab1_Click(PreviousTab As Integer)
' Refresh the report when clicking on the Preview tab
' Without refreshing the data from the server
If PreviousTab = 0 Then CRViewer1.RefreshEx False
End Sub
' *************************************************************
' Create a new report and display it in the Embeddable Designer
'
Private Sub cmdNew_Click()
On Error GoTo errhandler
' Set the report object to nothing
Set m_Report = Nothing
' Create a new report
Set m_Report = m_Application.NewReport
' Call the procedure to set the report to the Embeddable Designer
' and the Crystal Report Viewer and then display the report in the
' Embeddable Designer.
Call DisplayReport
Exit Sub
errhandler:
errString = "Error # " & CStr(Err.Number) & " " & Err.Description
errTitle = Err.Source
MsgBox errString, vbCritical, errTitle
End Sub
' *************************************************************
' Use the Microsoft Common Dialog control to open a report.
'
Private Sub cmdOpen_Click()
' Set Cancel to True
CommonDialog1.CancelError = True
On Error GoTo errhandler
' Filter the Open dialog box to display
' Crystal Reports files only.
CommonDialog1.Filter = OpenDialogFilter
CommonDialog1.InitDir = App.Path & "\report"
CommonDialog1.flags = &H1000 And &H8
' Display the open dialog box
CommonDialog1.ShowOpen
' Set the report object to nothing
Set m_Report = Nothing
' Open the selected report
Set m_Report = m_Application.OpenReport(CommonDialog1.FileName, 1)
' Call the procedure to set the report to the Embeddable Designer
' and the Crystal Report Viewer
Call DisplayReport
Exit Sub
errhandler:
Select Case Err.Number
Case 32755
'User cancelled dialog
Case Else
errString = "Error # " & CStr(Err.Number) & " " & Err.Description
errTitle = Err.Source
MsgBox errString, vbCritical, errTitle
End Select
End Sub
--------------------------------------------------------------------
Voici un exemple qui permet de manipuler certains objets, dans ce cas supprimer certains objets à l'impression:
'Impression automatique de 2 copies, la 2ème sans entête
'On Error GoTo Err_Print
Dim crystal As New CRAXDDRT.Application
Dim Report As New CRAXDDRT.Report
Dim CrObject As Object
Dim Robjects As CRAXDDRT.ReportObjects
'Ouverture du rapport
Set Report = crystal.OpenReport(App.Path & "\Report" & ReportFile & ".rpt")
Report.ReportTitle = WindowTitle
Report.ReadRecords
Report.RecordSelectionFormula = RecordSelector
Report.SelectPrinter Printers(PrinterA4).DriverName, Printers(PrinterA4).DeviceName, Printers(PrinterA4).Port
'Impression
Report.PrintOut False
'Impression sans entête
With Report.Sections(1)
Set Robjects = .ReportObjects
For Each CrObject In Robjects
If CrObject.Kind = CRAXDDRT.CRObjectKind.crOLEObject Then
CrObject.Suppress = True
End If
Next
End With
Report.PrintOut False
Set crystal = Nothing
Set Report = Nothing
Exit Sub
Err_Print:
Set crystal = Nothing
Set Report = Nothing
WriteToLog "PrintDirect : " & Err.Description
MsgBox Err.Description, vbApplicationModal + vbCritical + vbOKOnly, "Impression"
End Sub
arezkiTerkmani
Messages postés2Date d'inscriptiondimanche 21 janvier 2007StatutMembreDernière intervention15 novembre 2010 28 mars 2007 à 17:40
Bonjour chers Amis!
Ces échanges sont trés instructifs pour moi qui débute dans la programmation VB6. Je vous remercie donc pour toutes les précisions que j'y trouve..
j'en profite pour vous demander où je pourrais bien télécharger l'Ocx CRYSTL32.OCX ; Merci d'avance.
Arezki d'Alger . Email : [mailto:DELLYS6471@YAHOO.FR DELLYS6471@YAHOO.FR]