Jump to content

FileOpen Not Working

Go to solution Solved by alanbr00,

Recommended Posts

  • Solution

Hi, i'm trying to use an alternative to FileOpenDialog, FileOpen would work for me, but i can't get it work in this script.

#include <GUIConstants.au3>

AutoItSetOption("WinTitleMatchMode", 2)

Dim $sReportName
Dim $objCRApp
Dim $objCRReport
Dim $objCRViewer
Dim $CrystalExportOptions
Dim $ExportFileName
Dim $ExportType

;~$sReportName = FileOpenDialog("C:\test\zNC\engine\Vinhos\VinhosTotal", "", "RPT (*.rpt)", 3);Filter "." means all
$sReportName = FileOpen("C:\test\zNC\engine\Vinhos\VinhosTotal.rpt", "0")
$objCRApp = ObjCreate("CrystalRuntime.Application.11")
If $objCRApp = 0 Then
    MsgBox(0, "Error", "Could not create CrystalRuntime Application Object")
$objCRReport = $objCRApp.OpenReport($sReportName)
If $objCRReport = 0 Then
    MsgBox(0, "Error", "Could not open report: " & $sReportName)

$objCRViewer = ObjCreate("CrystalReports11.ActiveXReportViewer.1")

; Create a simple GUI for our output
;~ $hndReportViewer = GUICreate ( "Embedded Crystal Reports Export test", 640, 580,(@DesktopWidth-640)/2, (@DesktopHeight-580)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
;~ If $hndReportViewer = 0 Then
;~     MsgBox(0, "Error", "Could not create Window to display Crystal Reports control")
;~     Exit
;~ EndIf
;Creates an ActiveX control in the GUI.
;~ $GUIActiveX = GUICtrlCreateObj ( $objCRViewer, -1, -1, 640, 580)
;~ If $GUIActiveX = 0 Then
;~     MsgBox(0, "Error", "Could not create ActiveX Control in GUI")
;~     Exit
;~ EndIf
;~ GUICtrlSetResizing ( $GUIActiveX, $GUI_DOCKAUTO)

; Show GUI
;~ GUISetState ()

$objCRViewer.ReportSource = $objCRReport

; Display the Report to watch automation
; The report displays a "0" in control 20005 while the report is loading
While ControlGetText("Embedded Crystal Reports printing test", "", 20005) = "0"

$CrystalExportOptions = $objCRReport.ExportOptions
$ExportFileName = "C:\ERPSystem\zNC\engine\Vinhos\ExportedReport.PDF"
$ExportType = 31

$CrystalExportOptions.DiskFileName = $ExportFileName
$CrystalExportOptions.FormatType = $ExportType
$CrystalExportOptions.DestinationType = 1
$objCRReport.Export ( False )
WinWaitClose("Export", "", 30)


To solve my problem i just remove the "FileOpen" like that:

$sReportName = "C:\test\zNC\engine\Vinhos\VinhosTotal.rpt"

That way it will not prompt me to select the file.

Edited by alanbr00
Link to post
Share on other sites
43 minutes ago, Danp2 said:

Why do you want to open the file in AutoIt? This doesn't make sense to me because you are trying to pass the file handle from AutoIt into the object's OpenReport method. Wouldn't you just pass the file's full path into the method?

What i'm trying to do is generating the report and export to PDF. That script it's doing exacly that, but i dont want need to select the file with the "FileOpenDialog", i have tried to use "FileOpen" intead, but with no success.


Just solve my issue. Will add at beginning.

Edited by alanbr00
Found the solution.
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By JDGenesis
      EDIT:  Just realized I posted in the wrong section.  Can a moderator move this, please?
      Hello.  I've search the forums and internet many times and can't find a solution to my problem.  I started on a UDF to use Crystal Reports and want to be able to export a report multiple times during one run.  The problem lies in the record selection command.  It will work the first time, but randomly fails after that.  The error I get states "Basic syntax is not supported on a record or group selection formula".  The issue is i'm not using basic syntax and my formula doesn't change, just the string within the quotes.  The report will still export, but if the record selection fails then it will use the string saved in the report and not the one I tried to pass.  Below is the main program and I attached two of the include files.  I've considered using a parameter instead, but none of the code I've found online works when I try to pass a parameter.
      Global $vSaveFilePath = "C:\Users\public\desktop\test", _ $vReportFilePath = "C:\Program Files\Chameleon Software\Chameleon\Crystal", _ $aReportFileName = ["MedHist.rpt","Receipt.rpt","Vacc_Cert.rpt"], _ $aSelect[3] _Run() Func _Run() Local $aData = _DataQuery("query string") ;_ArrayDisplay($aData) If Not IsArray($aData) Then Exit MsgBox(0,"","Returned no records") For $x = 1 To UBound($aData) - 1 $aSelect[0] = "{KENNEL.IMPOUND_NO} = """ & $aData[$x][4] & """" $aSelect[1] = "{RECEIPT.RECEIPT_NO} = """ & $aData[$x][5] & """" $aSelect[2] = "{V_Rabies_Vac.tag_no} = """ & $aData[$x][6] & """" For $y = 0 To 2 ConsoleWrite($aSelect[$y] & @CRLF) If $aData[$x][$y + 4] <> "" Then _CrystalReportsExport($vReportFilePath & "\" & $aReportFileName[$y],"username","password", $aSelect[$y], $vSaveFilePath & "\" & $aData[$x][3] & "." & StringTrimRight($aReportFileName[$y],4) & "." & $aData[$x][4] & ".pdf") Next Next EndFunc 
  • Create New...