Results 1 to 4 of 4
  1. #1
    cfobare79 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Dec 2014
    Posts
    66

    Saving a report to table and saving as pdf with one button

    I have the code below. I keep getting this error: Run-time error '2501' The OutputTo action was canceled

    Private Sub Command192_Click()
    CurrentDb.Execute "INSERT INTO Report ( ReportNum, AgencyID, AgencyName, ServiceGroup, StartDate, EndDate, ServiceName ,Total) " & _
    " VALUES ('" & [Text137] & "'," & [AgencyID] & ",'" & [AgencyName] & "','" & _


    [ServiceGroup] & "',#" & [Text106] & "#,#" & [Text0] & "#,' " & [Label197].[Caption] & " ', ' " & [Text188] & " ')"




    Dim FileName As String
    Dim FilePath As String


    FileName = Me.Number
    FilePath = "C:\Users\Chris\Desktop\NYS ITS Storage\" & FileNme & ".pdf"
    DoCmd.OutputTo acOutputReport, "Enterprise Communications", acFormatPDF, FilePath
    MsgBox "Invoice Has Been Saved", vbInformation, "Sace Confirmed"
    End Sub

  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,902
    I see space between apostrophe and quote mark for the last two parameters in the INSERT statement. Probably don't want to save data with spaces.

    The variable FileName is misspelled in the FilePath concatenation.

    Every code module should have Option Explicit in the module header to help catch these type of errors.
    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
    cfobare79 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Dec 2014
    Posts
    66
    That was the problem.. .Thanks a lot. I don't know how I missed that after looking it over 100 times.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    As I said, Option Explicit in module header will help catch those errors.
    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.

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

Similar Threads

  1. Report changes not saving
    By khughes46 in forum Access
    Replies: 2
    Last Post: 01-30-2015, 02:35 PM
  2. Replies: 6
    Last Post: 11-14-2013, 07:37 AM
  3. Saving a report to pdf
    By tommy93 in forum Import/Export Data
    Replies: 5
    Last Post: 02-16-2013, 02:49 PM
  4. Saving records when a button is pushed
    By LAazsx in forum Programming
    Replies: 1
    Last Post: 11-28-2010, 10:06 PM
  5. VB coding for saving when click on save button in form
    By cwwaicw311 in forum Programming
    Replies: 1
    Last Post: 02-04-2010, 11:11 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