Full Version: Water is OVER the Head....
UtterAccess Forums > Microsoft® Access > Access Forms
doran_doran
Hi,
I am using following code to export PDF and it's working fine. See Sample Database for reference.
1. How do I prompt for location ? (like what drive or directory to save, end user will nagivate this). I tried http://www.mvps.org/access/api/api0001.htm but it's way over my head.
Feel free to modify the code accomodate "prompt for location"
Thanks
= = = = Working Code = = = =
Private Sub cmdSaveReportAsPDF_Click()
If ValidateRptData() = True Then
Dim ReportName As String
Dim FileName As String
Dim DateToday As Date
DateToday = Date
ReportName = "rptNP_Main"
FileName = ReportName & " - " & Format(DateToday, "mm-dd-yyyy") & ".pdf"
Call SaveReportAsPDF("rptNP_Main", FileName)
MsgBox "Export completed"
End If
End Sub
adaytay
Hi,

You didn't have the necessary API call to display the dialog box... so attached is a slightly revised version.

A few comments if I may:

1) You were using the same functions and subs in two forms. Rather than duplicating code, I've moved the common objects into a new module. The code will still refer to these as they are "Public" rather than "Private" functions.
2) Your code wouldn't compile, so I've commented out "GetDate" - it's obviously a custom function.
3) I've amended the code to detect Adobe Acrobat 6.0 as well as 5.0... untested though as I have neither on my machine!

Hope this is of some use. This isn't the "final working" version - but should give you a good indication of where to go next.

Ad
doran_doran
Thanks Adam for your prompt respond.
. Original code was working. All I needed is system to prompt a window for saving location and file name.
2. Your New one is same as my old one except few changes you made..
AM I MISSING SOMETHING ???
doran_doran
Anyone else willing to help ??? please
datAdrenaline
Why not prompt for the filename before you call the function to export to PDF ... The attached zip file has code in it that allows the user to call the Open/Save file dialogs ...
!--c1-->
CODE
.
.
    strFileName = osdOpenSaveFile()
    'Some code to ensure there is a file name with the .PDF extension
    'Some code to see if the user wants to overwrite an existing file
    
    SaveReportAsPDF("rpt402gdept", strFilename)

NOTE: CODED BUT NOT TESTED ... If the mdb doesn't work, please let me know (I converted from A2k to A97) ... If it doesn't work, I will send you a text version of the module ...
HTH
Brent
datAdrenaline
doran_doran
Can you please post the text module? Thanks

DB Included...
Edited by: doran_doran on Wed Oct 13 13:46:17 EDT 2004.
datAdrenaline
This code I sent is the same code that Adaytay has in the database he posted (module basBrowse) ... However, I would modify the SaveReportAsPDF code to look like this ...
!--c1-->
CODE
Public Sub SaveReportAsPDF(strReportName As String, Optional strPath As String)
    Dim strOldDefault As String
    Dim strFilter As String
          
    'Ask for the path if it is not provided
    If Trim(strPath) = "" Then
        strFilter = ahtAddFilterItem(strFilter, "Adobe PDF Files (*.pdf)", "*.pdf")
        strPath = ahtCommonFileOpenSave( _
                OpenFile:=False, _
                Filter:=strFilter, _
                Flags:=ahtOFN_OVERWRITEPROMPT Or ahtOFN_READONLY)
    End If
    strOldDefault = QueryKey("Software\Microsoft\Windows NT\CurrentVersion\Windows", "Device")
    
    SetKeyValue "Software\Microsoft\Windows NT\CurrentVersion\Windows", "Device", "Acrobat PDFWriter", REG_SZ
    
    SetKeyValue "Software\Adobe\Acrobat PDFWriter", "PDFFilename", strPath, REG_SZ
    
    SetKeyValue "Software\Adobe\Acrobat PDFWriter", "bExecViewer", 0, REG_SZ
    DoCmd.OpenReport strReportName
    
    SetKeyValue "Software\Microsoft\Windows NT\CurrentVersion\Windows", "Device", strOldDefault, REG_SZ
End Sub

In doing this, you could specify the file when calling the function OR if the strPath parameter is left blank, the function will prompt you for it.
For Example:
Call SaveReportAsPDF("rpt402gdept") .... App would prompt you for a file name
Call SaveReportAsPDF("rpt402gdept","c:\pdf\rpt402gdept.pdf") ... App WOULD NOT prompt you for a name.
Hope that helps ..
Brent
datAdrenaline
doran_doran
THANKS A BILLION BRENT......... WONDERFUL JOB. WORKED LIKE A CHARM. I AM NEW TO THIS AND IT WAS WAYYYYYYYYYYYYYYYYYYY OVER HEAD.
THANKS AGAIN.....
Shirly
doran_doran
Brent, Do you know how to set my printer back to HP Printer? B/c, you know i have print button the form and if I execute PDF before then it makes the pdf a default printer. I guess I have to reset the printer after calling SaveReportAsPDF..
Any help will be appreciated.
Thanks
datAdrenaline
From the looks of your code, the default should have been returned to the previous default ... I take it that is not what happens ...
rent
datAdrenaline
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.