Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Report Form command changing alias()
Message
 
 
To
02/11/2006 08:21:41
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01166325
Message ID:
01166600
Views:
15
Beth,

That's too much code for me to digest <g> I just spotted that in one message you put "must must".

Anyway, just to make sure to exclude possible problems, I can suggest the following workaround.

Put the following in the beginning of the button's code
local lnSelect, lcCurDir

lnSelect = select()
lcCurDir = SET("Default") + CURDIR()

then your current code

then before REPORT FORM put
cd (m.lcCurDir)
select (m.lnSelect)

See, if this rectifies the problem.


>The cReptFormFullName variable contains a full path and report name. I do not believe that the code changes any directory. Below is the code to the start report button.
>
>>Make sure to save current directory and restore it back, because some actions can unadvertantly change the directory...
>>
>< snip>
>
>* Click event for button [Start report] in form QM_RTYPE.SCX.
>PRIVATE cString
>IF NOT lQueryMakerRunThru
>  IF THISFORM.check1.VALUE = 1
>    llok = checkforemail(cQuery_id)
>    IF !llok
>      THISFORM.check1.VALUE = 0
>      THISFORM.REFRESH()
>    ENDIF
>  ELSE
>    goData = .NULL.
>  ENDIF
>ENDIF
>lErrorFound = .F.  && If true, then an incorrect file name was entered by user.
>nErrorLevel = 0    && Error level set by QM_ERROR() to signal back type of error.
>nName_width = LEN(cReport_name) + 4  && Width of report name field. plus lenght of ext if not there  bw 1/12/06
>nDirection = THISFORM.opg_direction.VALUE  && User selected output direction.
>
>** Security if implemented. Disable buttons to edit report.
>IF(glrptsecurity AND NOT lQueryMakerRunThru) THEN
>ELSE
>  THISFORM.btn_reset.ENABLED = .T.
>ENDIF
>
>CLEAR TYPEAHEAD
>DO CASE
>  CASE cOutput_type = "LABELS" .AND. .NOT. FILE(cLabelName + ".LBX")  && If printing mailing labels.
>    cString = "Before you can generate mailing labels, you must must "+;
>      "insert fields into the label.  To insert fields, first "+;
>      "pull down the Report menu and select the Variables option."
>    = MESSAGEBOX(cString, 0 + 48, "Missing Label Fields")
>    THISFORM.btn_edit.SETFOCUS
>    RETURN
>
>  CASE (nDirection = 2 .OR. nDirection = 4) .AND. EMPTY(cReport_name)  && If report name field empty, then assign default value.
>    cString = "Since you have directed output to a report file, "+;
>      "you must also type in a file name.  If you wish "+;
>      "to use the suggested name of QMF_REPT.TXT, then "+;
>      "just press the [Start report] button again."
>    IF (NOT(lQueryMakerRunThruWeb) AND (NOT(lQueryMakerRunThru)))
>      = MESSAGEBOX(cString, 0 + 48, "Must Supply A File Name")
>    ENDIF
>    cReport_name = PADR("QMF_REPT.TXT", nName_width)
>    THISFORM.REFRESH
>    RETURN
>
>  CASE nDirection = 2 .OR. nDirection = 4  && If disk file output selected.
>** check the file name for illegal characters and directory exists.
>   IF(RAT("\", cReport_name, 1) <= 0 AND NOT(EMPTY(cReport_name))) THEN
>     cReport_name = gPrintTables + cReport_name
>     nName_width = LEN(cReport_name) + 4  && Width of report name field.
>   ENDIF
>   lcOut_path = LEFT(cReport_name, RAT("\", cReport_name, 1))
>   IF(DIRECTORY(ALLTRIM(lcOut_path)) != .T.) THEN
>     IF (NOT(lQueryMakerRunThruWeb) AND (NOT(lQueryMakerRunThru)))
>       WAIT WINDOW 'File Path is Invalid. Please Select Output Path and Name Again.'
>       cReport_name = PUTFILE("Output Name: ")
>     ELSE
>       cReport_name = gPrintTables + "QMF_REPT.TXT"
>     ENDIF
>     nName_width = LEN(cReport_name) + 4  && Width of report name field.
>     THISFORM.REFRESH
>   ENDIF
>    IF .NOT. "." $ cReport_name  && If missing an extension, then add one.
>      cReport_name = PADR(ALLTRIM(cReport_name) + ".TXT", nName_width)
>      nName_width = LEN(cReport_name) + 4  && Width of report name field.
>      THISFORM.REFRESH
>    ENDIF
>
>    IF(nDirection = 2) THEN
>      IF UPPER(RIGHT(RTRIM(cReport_name), 4)) <> ".TXT"
>        cReport_name = IIF(LEFT(cReport_name, 1) <> ".", LEFT(cReport_name, AT(".", cReport_name) - 1) + ".TXT", "QMF_REPT.TXT")
>        cReport_name = PADR(cReport_name, nName_width)
>        cString = "Since you must include a .TXT file extension, your "+;
>          "file extension is being automatically changed to " + cReport_name
>        IF (NOT(lQueryMakerRunThruWeb) AND (NOT(lQueryMakerRunThru)))
>          = MESSAGEBOX(cString, 0 + 48, "Missing File Extension")
>        ENDIF
>      ENDIF
>    ELSE
>      IF UPPER(RIGHT(RTRIM(cReport_name), 4)) <> ".PDF"
>        cReport_name = IIF(LEFT(cReport_name, 1) <> ".", LEFT(cReport_name, AT(".", cReport_name) - 1) + ".PDF", "QMF_REPT.PDF")
>        cReport_name = PADR(cReport_name, nName_width)
>        cString = "Since you must include a .PDF file extension, your "+;
>          "file extension is being automatically changed to " + cReport_name
>        IF (NOT(lQueryMakerRunThruWeb) AND (NOT(lQueryMakerRunThru)))
>          = MESSAGEBOX(cString, 0 + 48, "Missing File Extension")
>        ENDIF
>      ENDIF
>    ENDIF
>
>    IF (NOT(lQueryMakerRunThruWeb) AND (NOT(lQueryMakerRunThru)))
>      IF(FILE(cReport_name)) THEN
>        IF(MESSAGEBOX(L_CNTSTU.FILEEXST, 4+32, ALLTRIM(L_QM_SQL.MSG56) + " " + ALLTRIM(cReport_name) + ")") != 6) THEN
>          RETURN (.F.)
>        ENDIF
>      ENDIF
>    ENDIF
>
>ENDCASE
>* If proceeding with the report, then save the user's changes.
>SELECT QM_LIST
>IF RLOCK()  && If query record secured.
>  IF QM_LIST.F_QUERY_ID = cQuery_id  && If another user hasn't deleted record.
>    REPLACE F_P_OUTPUT WITH nDirection, ;
>      F_P_NAME   WITH cReport_name, ;
>      F_P_EJECT  WITH lFirstEject
>  ENDIF
>  UNLOCK
>  GO RECNO()
>ENDIF
>
>IF QM_LIST.F_QUERY_ID <> cQuery_id
>  = MESSAGEBOX("Cannot proceed because the query was not found!", 0 + 48, "Cannot Proceed")
>  RETURN (.F.)
>ENDIF
>
>nErrorLevel = 0  && Can be changed on QM_ERROR() error handler.
>
>IF nDirection = 1 AND NOT lQueryMakerRunThru && If outputting to the printer.
>* Verify that printer is on line.
>  cMsg_text = "Please make sure that your printer is "+;
>    "turned on, loaded with paper, securely "+;
>    "connected and is on-line."
>  DO WHILE .NOT. PRINTSTATUS()
>    IF MESSAGEBOX(cMsg_text, 5+32, "Printer Cannot Be Accessed!") <> 4
>      RETURN (.F.)
>    ENDIF
>  ENDDO
>ENDIF
>
>ON ERROR DO QM_ERROR WITH "PRINT" && Install Query Maker's error handler.
>SELECT (cTable_name)           <--------- this is the alias that it should be on for the report.
>
>DO CASE
>  CASE (cOutput_type = "REPORT" .OR. cOutput_type = "FORM_REPT" .OR. cOutput_type = "DS_REPT") .AND. nDirection = 1  && Send report to printer.
>    WAIT "Printing the report . . . " WINDOW NOWAIT
>
>    PRINTJOB
>      IF NOT lQueryMakerRunThru
>        IF lFirstEject  && If eject page at report's beginning.
>          REPORT FORM (cReptFormFullName) NOCONSOLE TO PRINTER PROMPT
>        ELSE
>          REPORT FORM (cReptFormFullName) NOCONSOLE TO PRINTER PROMPT NOEJECT
>        ENDIF
>      ELSE
>        IF(PRINTSTATUS()) THEN
>          IF lFirstEject  && If eject page at report's beginning.
>            REPORT FORM (cReptFormFullName) NOCONSOLE TO PRINTER
>          ELSE
>            REPORT FORM (cReptFormFullName) NOCONSOLE TO PRINTER NOEJECT
>          ENDIF
>        ENDIF
>      ENDIF
>    ENDPRINTJOB
>
>    SET PRINTER TO  && Try to flush network print buffer, if any.
>
>  CASE (cOutput_type = "REPORT" .OR. cOutput_type = "FORM_REPT" .OR. cOutput_type = "DS_REPT") .AND. nDirection = 2  && Send report to file.
>    WAIT "Writing the report file " + RTRIM(cReport_name) + " . . . " WINDOW NOWAIT
>    IF lFirstEject  && If eject page at report's beginning.
>      REPORT FORM (cReptFormFullName) NOCONSOLE TO FILE (cReport_name) ASCII
>    ELSE
>      REPORT FORM (cReptFormFullName) NOCONSOLE NOEJECT TO FILE (cReport_name) ASCII
>    ENDIF
>    SET MESSAGE TO ""
>    WAIT CLEAR
>
>    IF NOT(lQueryMakerRunThruWeb)
>      IF MESSAGEBOX("Do you want to view this file now?", 4+32, "View " + ALLTRIM(cReport_name)) = 6
>        llok = opentextfile(cReport_name)
>      ENDIF
>    ENDIF
>    IF VARTYPE(goData) = "O"
>      llok = smtpmailwrapper(goData.ToName, goData.SubjectTo, goData.MsgBody, ;
>      IIF(!EMPTY(goData.AttachmentM),goData.AttachmentM, cReport_name), goData.FromName)
>      goData = .NULL.
>      RELEASE extended goData
>    ENDIF
>
>  CASE (cOutput_type = "REPORT" .OR. cOutput_type = "FORM_REPT" .OR. cOutput_type = "DS_REPT") .AND. nDirection = 3  && Send report to the screen.
>    REPORT FORM (cReptFormFullName) TO PRINTER PROMPT PREVIEW     <-----------This is the line that the alias is switching on for some reason.
>
>  CASE (cOutput_type = "REPORT" .OR. cOutput_type = "FORM_REPT" .OR. cOutput_type = "DS_REPT") .AND. nDirection = 4  && Send report to a PDF file.
>    WAIT "Writing the report file " + RTRIM(cReport_name) + " . . . " WINDOW NOWAIT
>      lnNumPrinters = APRINTERS(gaPrinters)
>      IF lnNumPrinters > 0  THEN && If there are installed printer drivers
>        lnPos = ASCAN(gaPrinters, 'Acrobat PDFWriter')
>        IF lnPos != 0 THEN
>** Write out to a postscript file and then translate to pdf if adobe installed
>          IF UPPER(RIGHT(RTRIM(cReport_name), 4)) <> ".TXT"
>            lcReportName = cReport_name + ".PS"
>          ELSE
>            lndotpos = AT('.', cReport_name, 1)
>            lcReportName = SUBSTR(cReport_name, 1, lndotpos) + "PS"
>          ENDIF
>          SET PRINTER TO NAME "Acrobat PDFWriter"
>          STORE PRINTSTATUS( ) TO llReady
>          IF NOT llReady
>            SET PRINTER TO DEFAULT
>            REPORT FORM (cReptFormFullName) NOCONSOLE TO FILE (cReport_name) ASCII
>          ELSE
>            REPORT FORM (cReptFormFullName) NOCONSOLE TO FILE (lcReportName)
>            SET PRINTER TO DEFAULT
>            lcReportName2 = STRTRAN(lcReportName, ".PS", ".PDF")
>            IF FILE(lcReportName2) THEN
>              Fhandle = FOPEN(lcReportName2)
>              DO WHILE  Fhandle = -1
>                Fhandle = FOPEN(lcReportName2)
>              ENDDO
>              FCLOSE(Fhandle)
>            ENDIF
>            IF(FILE(lcReportName)) THEN
>              DELETE FILE (lcReportName)
>            ENDIF
>          ENDIF
>        ELSE
>          lnPos = 0
>          FOR lncnt = 1 TO lnNumPrinters
>            IF(RIGHT(gaPrinters(lncnt, 1),2) == 'PS') THEN
>              lnPos = lncnt
>            ENDIF
>          ENDFOR
>          IF lnPos != 0 THEN
>** Use a postscript and Ghostscript instead of Adobe
>            IF UPPER(RIGHT(RTRIM(cReport_name), 4)) <> ".PDF"
>              lcReportName = cReport_name + ".PS"
>            ELSE
>              lndotpos = AT('.', cReport_name, 1)
>              lcReportName = SUBSTR(cReport_name, 1, lndotpos) + "PS"
>            ENDIF
>            IF FILE(lcReportName) THEN
>              DELETE FILE (lcReportName)
>            ENDIF
>            SET PRINTER TO NAME gaPrinters(lnPos,1)
>            STORE PRINTSTATUS( ) TO llReady
>            IF NOT llReady
>              SET PRINTER TO DEFAULT
>              REPORT FORM (cReptFormFullName) NOCONSOLE TO FILE (cReport_name) ASCII
>            ELSE
>              REPORT FORM (cReptFormFullName) NOCONSOLE TO FILE (lcReportName)
>
>              SET PRINTER TO DEFAULT
>              lcExeName = ALLTRIM(gMainPath) + 'bin\gswin32c.exe' + ;
>                ' -I' + ALLTRIM(gMainPath) + 'lib;' + ALLTRIM(gMainPath) + 'fonts' + ;
>                ' -dCompatibilityLevel=1.2' + ;
>                ' -q -dSAFER -dNOPAUSE -dBATCH -sDEVICE=pdfwrite' + ;
>                ' -sOutputFile=' + '"' + ALLTRIM(STRTRAN(lcReportName, '.PS', '.PDF')) + '"' + ;
>                ' -c .setpdfwrite -f ' + '"' + ALLTRIM(lcReportName) + '"' + CHR(0)
>*!*	            RUN /N &lcExeName
>              WAIT "Writing the report PDF " + RTRIM(cReport_name) + " . . . " WINDOW NOWAIT NOCLEAR
>              DO ps2pdf WITH lcExeName
>              SET MESSAGE TO ""
>              WAIT CLEAR
>              WAIT "Finished the report PDF " + RTRIM(cReport_name) + " . . . " WINDOW NOWAIT
>
>              IF(FILE(lcReportName)) THEN
>                DELETE FILE (lcReportName)
>              ENDIF
>            ENDIF
>          ENDIF
>        ENDIF
>      ENDIF
>    SET MESSAGE TO ""
>    WAIT CLEAR
>    IF VARTYPE(goData) = "O"
>      llok = smtpmailwrapper(goData.ToName, goData.SubjectTo, goData.MsgBody, ;
>      IIF(!EMPTY(goData.AttachmentM),goData.AttachmentM, cReport_name), goData.FromName)
>      goData = .NULL.
>      RELEASE extended goData
>    ENDIF
>
>  CASE cOutput_type = "LABELS" .AND. nDirection = 1  && Send labels to printer.
>    WAIT "Printing the labels . . . " WINDOW NOWAIT
>    PRINTJOB
>      LABEL FORM (cLabelName) NOCONSOLE SAMPLE TO PRINTER PROMPT
>    ENDPRINTJOB
>    SET PRINTER TO  && Try to flush network print buffer, if any.
>
>  CASE cOutput_type = "LABELS" .AND. nDirection = 2  && Send labels to file.
>    WAIT "Writing the label file " + RTRIM(cReport_name) + " . . . " WINDOW NOWAIT
>    LABEL FORM (cLabelName) NOCONSOLE TO FILE (cReport_name)
>
>  CASE cOutput_type = "LABELS" .AND. nDirection = 3  && Send labels directly to the screen.
>    LABEL FORM (cLabelName) PREVIEW SAMPLE
>ENDCASE
>
>IF nDirection = 1 .AND. nErrorLevel = 0  && If output sent to printer.
>  WAIT "Finished" WINDOW NOWAIT
>ENDIF
>
>IF EMPTY(cErrorHandler)  && Remove Query Maker's error handler.
>  ON ERROR
>ELSE        && Restore prior error handler.
>  ON ERROR &cErrorHandler
>ENDIF
>
>IF nDirection = 2 .AND. nErrorLevel = 0  && If output sent to a disk file.
>  IF .NOT. FILE(cReport_name)  && If the file exists.
>    = MESSAGEBOX("Unable to create the file " + RTRIM(cReport_name), 0 + 48, "No File Created")
>  ENDIF
>ENDIF
>
>
>
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform