Hello All this is my second project:
(With a lot of help of SvenP, Thanks)
This is a CR Report Viewer using AutoIt, making it a nice reporting engine.
But I need some help in catching the file from the Menu -> file Open.
And use that one in the variable $oReport (line 53) instead of the hard coded path and file name
#include <GUIConstants.au3> ; ; Embedding an Crystal Reports Viewer control inside an AutoIt GUI ; ; THIS EXAMPLE REQUIRES THE CRYSTAL REPORTS ACTIVEX VIEWER CONTROL V8.0 or higher !! ; ; The Crystal Reports ActiveX viewer is a component from the Crystal Reports suite and can not be obtained separately ; ; See also: <a href='http://support.businessobjects.com/' class='bbc_url' title='External link' rel='norewrite nofollow external'>http://support.businessobjects.com/</a> , search for "ActiveX" ; Initialize my error handler $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") Dim $Gui_edit Dim $Gui_fileExit Dim $file ; You can test this from: ; <a href='https://emr.kcms.msu.edu/touchworks/Common/Components/Printing/activexviewer.cab' class='bbc_url' title='External link' rel='norewrite nofollow external'>https://emr.kcms.msu.edu/touchworks/Common/Components/Printing/activexviewer.cab</a> ; expand the cab and run regsvr32.exe on the file crviewer.dll $oCRViewer = ObjCreate("CRViewer.CRViewer"); Create a Crystal Reports Viewer control $oCRViewerEvt = ObjEvent($oCRViewer,"CRViewerEvent_") ; Catch events from the control if IsObj($oCRViewer) then $oCRViewer.DisplayBorder = False ;MAKES REPORT FILL ENTIRE FORM $oCRViewer.DisplayTabs = True ;THIS REPORT DOES NOT DRILL DOWN, NOT NEEDED $oCRViewer.EnableDrillDown = True ;REPORT DOES NOT SUPPORT DRILL-DOWN $oCRViewer.EnableRefreshButton = True ;ADO RECORDSET WILL NOT CHANGE, NOT NEEDED #comments-start ; Using a local database and the crystal reports application ; Example from: <a href='http://www.vbmysql.com/samplecode/cr9vbmysql.html' class='bbc_url' title='External link' rel='norewrite nofollow external'>http://www.vbmysql.com/samplecode/cr9vbmysql.html</a> ; Open your data source here.... $conn = CreateObj("ADODB.Connection") $conn.CursorLocation = $adUseClient ;SERVER-SIDE NOT RECCOMENDED $conn.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};" _ & "SERVER=127.0.0.1;" _ & "DATABASE=test;" _ & "UID=testuser;" _ & "PWD=12345;" _ & "OPTION=" & 1 + 2 + 8 + 32 + 2048 + 16384 ;SET ALL PARAMETERS $conn.Open ; Create a recordset $rs = CreateObj("ADODB.Recordset") $rs.Open("SELECT * FROM report", $conn, $adOpenStatic, $adLockReadOnly) #comments-end ;MANAGES REPORTS $oCrystal = ObjCreate("CrystalRunTime.Application") $oReport = $oCrystal.OpenReport("C:TmpWeek Capacity Utilized by Machine.rpt") ;OPEN OUR REPORT ; Link the data source to your report ;$oReport.DiscardSavedData ;CLEARS REPORT SO WE WORK FROM RECORDSET ;$oReport.Database.SetDataSource $rs ;LINK REPORT TO RECORDSET ; Now link the viewer with the report $oCRViewer.ReportSource = $oReport ; Using a web server connection ; See also: <a href='http://support.businessobjects.com/communityCS/TechnicalPapers/cr_troubleshooting_activex_viewer.pdf' class='bbc_url' title='External link' rel='norewrite nofollow external'>http://support.businessobjects.com/communityCS/TechnicalPapers/cr_troubleshooting_activex_viewer.pdf</a> ;$oWebBroker = ObjCreate("WebReportBroker.WebReportBroker") ;$oWebSource = ObjCreate("WebReportSource.WebReportSource") ;$oWebSource.ReportSource = $oWebBroker ;$oWebSource.URL = "file:///C:TmpIT costs 2005.rpt" ; Change this to your URL. ;$oWebSource.PromptOnRefresh = True ; Now link the Webviewer with the report ;$oCRViewer.ReportSource = $oWebSource ; Create a simple GUI for our output GUICreate ( "Embedded ActiveXcrystal", 780, 740 ) ; Create File Menu $GUI_FileMenu = GUICtrlCreateMenu ("&File") ;$GUI_FileNew = GUICtrlCreateMenuitem ("&New" ,$GUI_FileMenu) $GUI_FileOpen = GUICtrlCreateMenuitem ("&Open..." ,$GUI_FileMenu) ;$GUI_FileSave = GUICtrlCreateMenuitem ("&Save" ,$GUI_FileMenu) ;$GUI_FileSaveAs = GUICtrlCreateMenuitem ("Save As..." ,$GUI_FileMenu) $GUI_FileSepa = GUICtrlCreateMenuitem ("" ,$GUI_FileMenu) ; create a separator line $GUI_FileExit = GUICtrlCreateMenuitem ("E&xit" ,$GUI_FileMenu) $GUI_ActiveX = GUICtrlCreateObj ( $oCRViewer, 10, 10 , 750 , 580 ) $GUI_Edit = GUICtrlCreateEdit ( "", 10, 600 , 750 , 120 ) GUISetState () ;Show GUI $oCRViewer.ViewReport ;Show Report ; Waiting for user to close the window While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $GUI_FileExit ExitLoop Case Else if $msg = $GUI_FileOpen Then $file = FileOpenDialog("Select RPT Source File", ".", "RPT (*.rpt)", 3);Filter "." means all EndIf EndSelect Wend GUIDelete () EndIf Exit ; This is my custom error handler Func MyErrFunc() $HexNumber=hex($oMyError.number,8) Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oMyError.description & @CRLF & _ "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _ "err.number is: " & @TAB & $HexNumber & @CRLF & _ "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _ "err.source is: " & @TAB & $oMyError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oMyError.helpcontext _ ) SetError(1) ; to check for after this function returns Endfunc ; -----Catch all CRViewer events Func CRViewerEvent_($Event) If Isdeclared("GUI_Edit") then GUICtrlSetData($GUI_Edit,"CRViewer Unused Event: " & $Event & @CRLF, "append") EndFunc ; Catch the print button event Func CRViewerEvent_PrintButtonclicked() MSgbox (0,"Print?","Print button clicked!") EndFunc
Attached is a sample CR Report for testing
The sooner I have reply, the sooner I can share this among the Forum users.
Edited by ptrex, 14 September 2012 - 09:00 AM.




