Results 1 to 12 of 12
  1. #1
    Join Date
    Nov 2012
    Posts
    20

    Unanswered: OutPut to Command Error 2051

    Hi, Please can someone help me figure out why I am getting Error 2051 "Outputto action was cancelled"

    My coding is as follows:

    Private Sub Command77_Click()
    If Me.FolderName = "January" Then
    Dir ("\\DISKSTATION\Innovative Physics\Admin\Invoices, Quotes, Credit Notes and Purchase Orders\Invoices Sent\2013\January\" & "Job#" & Space(3) & Me.Job_Number & Space(3) & Me.Job_Description & "\" & "Outgoing")
    End If
    Dim MyFileName As String
    Dim MyPath As String
    MyPath = "\\DISKSTATION\Innovative Physics\Admin\Invoices, Quotes, Credit Notes and Purchase Orders\Invoices Sent\2013\January\"
    MyFileName = "IPL" & Space(1) & Me.Company_Code & Space(1) & "13" & Space(2) & Me.Sales_Invoice & ".pdf"
    DoCmd.OutputTo acOutputReport, "rptSalesInvoice", acFormatPDF, MyPath & MyFileName, False
    End Sub

    I have looked through many threads and have been able to solve this issue.

  2. #2
    Join Date
    Nov 2011
    Posts
    413
    If Err.Number = 2051 Then
    End If

  3. #3
    Join Date
    Nov 2012
    Posts
    20
    Thank you for the quick reply.

    I have tried that...still get the error message.

  4. #4
    Join Date
    Nov 2011
    Posts
    413
    Try adding this to the bottom of your code:

    Error_Handler:
    Select Case Err.Number
    Case 2501
    Err.Clear
    Resume Error_Handler_Exit
    Case Else
    MsgBox "Error No. " & Err.Number & vbCrLf & "Description: " & Err.Description, vbExclamation, "Database Error"
    Err.Clear
    Resume Error_Handler_Exit
    End Select

  5. #5
    Join Date
    Nov 2012
    Posts
    20
    Thank you for your help. I get the error message label not defined on

    Resume Error_Handler_Exit

  6. #6
    Join Date
    Nov 2011
    Posts
    413
    Code should have read 2051 instead of 2501, My Bad! Please correct and let me know what happens.

  7. #7
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    I suspect its to do with the file name
    to test that hypothesis save the file to short simple location
    ..cut out the crap (the punctuation, spaces and so on)
    ..just send it to a simple location with simple filename
    see if that fixes it
    eg:-
    Code:
    MyPath = "C:\"
    MyFileName = format(now(),"YYYYMMDDHHMMSS")  & ".pdf"
    ..that will save the report as a timestamp (say its 01:23:45 today then the above will resolve to 2013081601245.pdf
    ..unless you try to run the code more that once per second it will always be unique.
    bear in mind all the above is trying to do is to have a short path and file name, which is unique (no other sources of error)

    there's lots of reasons
    1) you may be blowing some internal buffer inside Access.
    2) you may be blowing some code inside the PDF converter.
    3) you may be breaking something deep in the bowels of Access, which bear in mind dates back to the good old days of 8.3 filenames.
    check you do not already have an open copy of that pdf
    check that there isn't a version of that file already in existence. I don't know how the PDF export handles file already exists
    do you actually mean error 2051 or do you mean error 2501?

    if using the simple code above works then you can start getting fancy
    actually I'd suggest you comment out your existing code, see if my suggestion works then gradually bring different elements back into play
    ...is it your path or your filename that is blowing the system
    ...do company_code and SalesInvoice alwasy have a value or are they NULL. if NULL that could be the source of the problem
    can we see the result (the values of mypath and myfilename)

    i dont know what you are doing with the dir command at the head of the function....

    personally the path name is pants
    instead of
    \\DISKSTATION\Innovative Physics\Admin\Invoices, Quotes, Credit Notes and Purchase Orders\Invoices Sent\2013\January\"
    you should get the same effect with
    MyPath = "\\DISKSTATION\IPL\Admin\Financial\INV\" 'for invoices
    MyPath = "\\DISKSTATION\IPL\Admin\Financial\CN\" 'for credit notes
    MyPath = "\\DISKSTATION\IPL\Admin\Financial\PO\" 'for Purchase Orders
    bear in mind this sort of document can be regarded as a legal document so there may well be good reasons why you cannot have 'versions' of it. so all you really need is a single ref
    so if I were you I'd only have the document number ( the invoice, credit note or PO number) plus a suitable suffix if required
    storing such financial document as a PDF can be a smart call... becuase if the customer is playing the none payment game you can always fire off copies of the invoice, credit note and or purchase order number by email.

    the error you are gettign with the handling code is that you must define a label where the code jumps to

    in this case I'd replace the final Resume Error_Handler_Exit with Error_Handler_Exit: however that isn't going to fix the problem just merely allow you code to keep running. the cause of the problem is that Access is failing to open the report AND save it as a PDF
    Last edited by healdem; 08-16-13 at 15:13.
    I'd rather be riding on the Tiger 800 or the Norton

  8. #8
    Join Date
    Nov 2012
    Posts
    20
    Burrina, Thank you unfortunately I am still getting the same error message.

    Healdem, Thank you for your thorough response. You are right, it is working with the path: \\DISKSTATION\Innovative Physics\Admin\Invoices, Quotes, Credit Notes and Purchase Orders\Invoices Sent\2013\January\"

    The part that breaks it is \" & "Job#" & Space(3) & Me.Job_Number & Space(3) & Me.Job_Description & "\" & "Outgoing"

    My colleagues would like the PDF to save automatically into the folder depending on the Job number and then into the folder Outgoing.

    I am rather a novice with VBA and therefore any help to make this automatic.

  9. #9
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    if thats the bit that breaks the system...
    then you need to diagnose whats causing the fault
    first off does the directory exist? I dint know if you can create a directory as part of DoCmd.OutputTo
    does your colleague really really need to have such a convoluted directory structure, especially one including a year and month

    what does "\\DISKSTATION\Innovative Physics\Admin\Invoices, Quotes, Credit Notes and Purchase Orders\Invoices Sent\2013\January\" & "Job#" & Space(3) & Me.Job_Number & Space(3) & Me.Job_Description & "\" & "Outgoing" actually resolve to
    put a breakpoint on the code and then copy and paste the above into the immediate window prefixed by a ?

    or msgbox("\\DISKSTATION\Innovative Physics\Admin\Invoices, Quotes, Credit Notes and Purchase Orders\Invoices Sent\2013\January\" & "Job#" & Space(3) & Me.Job_Number & Space(3) & Me.Job_Description & "\" & "Outgoing")

    I don't know what the limit for directory name lengths is, it may not have one, but its also entorely possible that you are blowing an internal limit in Access or the OS. try to crfeate a file with that name and see if the OS will accept it. Bear in mind Access dates back to he late 1980's and its quite possibel there is some code lurking which has problems with incredably long and silly directory/filenames
    I'd rather be riding on the Tiger 800 or the Norton

  10. #10
    Join Date
    Nov 2012
    Posts
    20
    Yes the directory \\DISKSTATION\Innovative Physics\Admin\Invoices, Quotes, Credit Notes and Purchase Orders\Invoices Sent\2013\January does exist, I have set this has been set up already by my colleague as to where the PDFs should go.

    When we receive an order from a customer, we will assign a "Job Number" to it. And create a Job Order form which creates the extra part of the directory when saved: \\DISKSTATION\Innovative Physics\Admin\Invoices, Quotes, Credit Notes and Purchase Orders\Invoices Sent\2013\January\" & "Job#" & Space(3) & Me.Job_Number & Space(3) & Me.Job_Description & "\" & "Outgoing

    Then when we create an invoice to send to a customer related to that Job Number my colleague wants the PDF to save into that Job Number folder automatically (I have the job number and description on the report).

    I tried the msgbox and still get the 2501 error Outputto Cancelled, maybe I have done it wrong?

    I think you are right in the way that the folders are silly and very long, I will discuss with my colleague about getting them smaller and simpler. I think the best solution is to get it into the correct month and then manually move the folder in to the Job number.

    Thank you for all your help

  11. #11
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    what is the value of MyFilename?
    as said before put a breakpoint on the code and examine that variable, make certain it makes sense.
    or output it to a msgbox BEFORE the code craps out.

    I cannot understand the point of hardcoding they year and month as directories.. thats just plain silly in my books. if you need that information then prefix the yearmonthday onto the filename and it will self sort, or jobno + dateinformation

    my un.dderstanding from post #8 that the code works without this extended path and or filename. thats where your investigation should be
    check those variables contain valid data
    check its not too long
    check what happens if you try to create a file
    check what happens if the file already exists
    I'd rather be riding on the Tiger 800 or the Norton

  12. #12
    Join Date
    Nov 2012
    Posts
    20
    Sorry for the delay in replying.

    Thank you for all your help!! I have it now sorted, it works with this coding:

    If Me.FloderName2 = "January" Then
    Dim MyFileName1 As String
    Dim MyPath1 As String
    MyFileName1 = "ALL SALES INVOICE JOB#" & Space(1) & Me.Job_Number & ".pdf"
    MyPath1 = "\\DISKSTATION\Innovative Physics\Admin\Invoices, Quotes, Credit Notes and Purchase Orders\Invoices Sent\2013\January\" & "Job#" & Space(3) & Me.Job_Number & Space(3) & Me.Job_Description & "\"
    DoCmd.OutputTo acOutputReport, "rptAllSales", acFormatPDF, MyPath1 & MyFileName1, False
    End If

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •