Results 1 to 14 of 14
  1. #1
    augcorv@gmail.com is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Feb 2014
    Posts
    20

    Exporting Report to PDF specific location on quit - over-writing existing

    Hello All, Im a newb to Access.
    Im attempting to export a report on database quit. Ive accomplished the export to a specific location with no problem.

    The issue i am having is that when I quit the database and it exports, it prompts me, "Do you want to replace the existing file?" I want to bypass that and allow the file to be overwritten on every quit with no prompt.

    What can i include in my Macro command to bypass the notification?

    My current macro goes as follows:
    ExportWithFormatting
    Object Type Report
    Object Name NameofReport
    Output Format: PDF Format
    Output File: C:\Users\etc\etc\filename.pdf
    Auto Start: No
    Template File
    Encoding


    Output Quality Print
    QuitAccess
    Options Save All

    Any suggestions or guidance would be appreciated.
    Thank you.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I don't use macros, only VBA. I am not seeing an argument for ExportWithFormatting action that will automatically overwrite file.

    Some events have a Response argument that can be used to automate response to popups and continue code execution. Example:

    Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
    'Suppress default Delete Confirm dialog box.
    Response = acDataErrContinue
    'cancel the automatic delete operation
    Cancel = True
    MsgBox "Must click Remove Test button to delete test from sample." , , "Delete"
    End Sub

    Unfortunately, that probably won't apply to your situation.

    In VBA I would first check if the file already exists and if found, delete it, then do the export.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    augcorv@gmail.com is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Feb 2014
    Posts
    20
    I'm still having a problem with this function. I've tried creating a module to delete the file first, then proceed with the Macro (exporting report to PDF) but still having problems. Any suggestions or guidance would be appreciated.

    My DeleteFile Module is:
    'Add a reference to Scripting Runtime

    Dim fso As New FileSystemObject

    If fso.FileExists("H:\testingexport\testexport.pdf") Then
    If MsgBox("That file exist, delete?", vbYesNo) = vbYes Then
    fso.DeleteFile ("H:\testingexport\testexport.pdf")
    End If
    Else
    MsgBox "Do not exist"
    End If

    set fso = nothing

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    You will have to describe the problem. Have you tested the function to delete the file? Perhaps you can start there by placing the code behind the click event of a button on a new blank form. Test the function by itself.

  5. #5
    augcorv@gmail.com is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Feb 2014
    Posts
    20
    If this Macro to Module approach is not suggested, how would i code a function to:
    Within FORM:
    On "BUTTON" selection:
    Check to see if file.pdf exists, and if so, delete file.pdf - THEN

    Export "Report" as PDF to "NetworkMappedDrive".
    What im trying to achieve is whenever the database is updated, a report of all entries will be exported (PDF format) to a network drive. Boss wants to see reports pdf format.

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    All that I am suggesting is to test your VBA using a button and a form.


    You can add VBA to the click event by selecting the Control Button while in Design View. Go to the property sheet and click the "Event Tab". There will be a list of events available. Select the ellipses(...) next the On Click field and then select "Code Builder" from the options. A new Click Event Handler in the VBA editor will appear. Your code will go between the first and last lines. Be sure to not include the first and last lines of your function.

    Here is a picture of the ellipses button in the property sheet. You want to select the Event Tab and then the appropriate Event.

    Click image for larger version. 

Name:	QueryBuilderCombo.jpg 
Views:	10 
Size:	51.9 KB 
ID:	15849

  7. #7
    augcorv@gmail.com is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Feb 2014
    Posts
    20
    thanks "ItsMe", when i do what you suggest, i recieve a compile error: User-defined type not defined. And it Highlights:
    Dim fso As New FileSystemObject.

    Code is as follows:


    Private Sub Command203_Click()


    'Add a reference to Scripting Runtime


    Dim fso As New FileSystemObject


    If fso.FileExists("H:\testingexport\testexport.pdf") Then
    If MsgBox("That file exist, delete?", vbYesNo) = vbYes Then
    fso.DeleteFile ("H:\testingexport\testexport.pdf")
    End If
    Else
    MsgBox "Do not exist"
    End If


    Set fso = Nothing


    End Sub

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Sounds like a missing reference. You will need to add a reference. In your VBA editor, go to Tools>References. You will see a References window. Scroll down to Microsoft Scripting Runtime and select it. Click OK.



    Click image for larger version. 

Name:	Scripting.jpg 
Views:	10 
Size:	59.2 KB 
ID:	15853

  9. #9
    augcorv@gmail.com is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Feb 2014
    Posts
    20
    Ok, got that - Now im getting a Compile error: Invalid outside procedure - Highlighting the filepath.

    Option Compare Database


    ''''
    ' Start Code '
    ''''


    'Add a reference to Scripting Runtime


    Dim fso As New FileSystemObject


    If fso.FileExists("H:\testingexport\testexport.pdf") Then
    If MsgBox("That file exist, delete?", vbYesNo) = vbYes Then
    fso.DeleteFile ("H:\testingexport\testexport.pdf")
    End If
    Else
    MsgBox "Do not exist"
    End If


    Set fso = Nothing

  10. #10
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Do you mean it is highlighting
    If fso.FileExists("H:\testingexport\testexport.pdf") Then
    ????

    You have two lines with file paths so it will help if you can detail exactly which line is causing the exception/error.

  11. #11
    augcorv@gmail.com is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Feb 2014
    Posts
    20
    Yes, Its highlighting,
    If fso.FileExists("H:\testingexport\testexport.pdf") Then

  12. #12
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    You need to place the code inside of an event handler. Take a look at post #6 again. Here is a sample DB.
    Attached Files Attached Files

  13. #13
    augcorv@gmail.com is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Feb 2014
    Posts
    20
    This works, but im still getting a popup asking "That file exist, delete?".

    Possibly something wrong in this code?
    If MsgBox("That file exist, delete?", vbYesNo) = vbYes Then

  14. #14
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    That is what the code does. It is prompting you to make a decision on whether or not to delete the file. If you want to bypass the message box, simply replace

    If MsgBox("That file exist, delete?", vbYesNo) = vbYes Then
    fso.DeleteFile ("H:\testingexport\testexport.pdf")
    End If

    with

    fso.DeleteFile ("H:\testingexport\testexport.pdf")

    After you sort out how you want your VBA to work, you can place the code back into your function and then work on the issue of getting hte macro to call the function. Or you could bring everything into VBA. Let us know...

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 10
    Last Post: 12-07-2012, 01:57 PM
  2. exporting access report to specific excel cells
    By grgold14 in forum Import/Export Data
    Replies: 1
    Last Post: 02-07-2012, 04:38 PM
  3. Replies: 0
    Last Post: 02-25-2011, 09:40 AM
  4. Exporting XML with existing XSD
    By royf in forum Import/Export Data
    Replies: 0
    Last Post: 06-20-2010, 10:48 AM
  5. Exporting from Query to existing Excel wksht
    By kfschaefer in forum Import/Export Data
    Replies: 0
    Last Post: 04-07-2006, 02:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums