Results 1 to 15 of 15
  1. #1
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276

    Need Vb Code Help Output To PDF

    Where am I making a mistake in this code, I could not figure out. Need Help




    DoCmd.OutputTo ObjectType:=acOutputReport, ObjectName:="General Sales", OutputFormat:=acFormatPDF, Outputfile:="C:\Users\ABC\Desktop (" + CurrentDay + "-" + CurrentMonth + "-" + CurrentYear + ").PDF", False, "", 0, acExportQualityPrint

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    vFile ="C:\Users\ABC\Desktop" & "(" & format(date(),"dd-mm-yyyy") & ").PDF"
    vRpt = "General Sales"
    DoCmd.OutputTo acOutputReport, vRpt, acFormatPDF, vFile

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You're also going to need a backslash after "desktop". I'd use a variable for the path so you can see how it's ending up:

    http://www.baldyweb.com/ImmediateWindow.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Forum post may have dropped last backslash. Posting between CODE tags should prevent that.
    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.

  5. #5
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276
    its not working

    the complete code is as follows

    Private Sub Command19_Click()
    On Error GoTo Err_Handler

    Const ReportName = "General Sales"
    Const MESSAGETEXT = "No customer selected."
    Dim strCriteria As String


    strCriteria = "CoId = " & Me.cboCustomers


    If Not IsNull(Me.cboCustomers) Then

    DoCmd.OpenReport ReportName, _
    View:=acViewPreview, _
    WhereCondition:=strCriteria


    vFile = "C:\Users\ABC\Desktop\PDF Reports" & "(" & Format(Date, "dd-mm-yyyy") & ").PDF"
    vRpt = "General Sales"
    DoCmd.OutputTo acOutputReport, vRpt, acFormatPDF, vFile


    Else
    MsgBox MESSAGETEXT, vbExclamation, "Invalid operation"
    End If

    Exit_Here:
    Exit Sub

    Err_Handler:
    MsgBox Err.Description, vbExclamation, "Error"
    Resume Exit_Here

    End Sub

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    What does "not working" mean exactly? Does the report open? What is the final value in vFile?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Please post code between CODE tags so we can be sure missing backslash is due to forum dropping and not really missing in code. Also, to retain indentation and readability.
    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.

  8. #8
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276
    am getting the compile error variable not defined

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    On which line?

    Error handlers interfere with debugging. Disable the On Error GoTo line and then run procedure.

    Why would you have a CONST for report name as well as a variable?

    Do you have Option Explicit in the module header?

    Variables vFile and vRpt are not declared.

    Should set variable strCriteria after verifying combobox is not null because strCriteria cannot hold Null and would error if it tried.
    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.

  10. #10
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276
    i used the following code and it works

    Private Sub Command17_Click()
    On Error GoTo Err_Handler

    Const ReportName = "General Sales"
    Const MESSAGETEXT = "No customer(s) selected"

    Dim varItem As Variant
    Dim strCustomerIDList As String
    Dim strCriteria As String
    Dim ctrl As Control

    Set ctrl = Me.lstCustomers

    If ctrl.ItemsSelected.Count > 0 Then
    For Each varItem In ctrl.ItemsSelected
    strCustomerIDList = strCustomerIDList & "," & ctrl.ItemData(varItem)
    Next varItem

    ' remove leading comma
    strCustomerIDList = Mid(strCustomerIDList, 2)

    strCriteria = "CoId In(" & strCustomerIDList & ")"

    DoCmd.OpenReport ReportName, _
    View:=acViewPreview, _
    WhereCondition:=strCriteria






    DoCmd.OutputTo ObjectType:=acOutputReport, ObjectName:="General Sales", OutputFormat:=acFormatPDF, Outputfile:="C:\Users\ABC\Desktop\PDF Reports\AC-Title Sale" & " " & Format(Date, "dd-mmm-yyyy") & ".PDF"


    Else
    MsgBox MESSAGETEXT, vbExclamation, "Invalid operation"
    End If


    Exit_Here:
    Exit Sub

    Err_Handler:
    MsgBox Err.Description, vbExclamation, "Error"
    Resume Exit_Here


    End Sub

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Glad you got it working.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276
    I am not sure if my method is correct or not?

  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I thought you said it worked? The only thing I see offhand is that I'd probably close the report after the export, but maybe you want it left open.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #14
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276
    Yes indeed it works, maybe i was not able to explain properly.
    what I was trying to say was can you check the code that it is correct. Your reply confirms that it is correct. Yes I wanted the report to stay open and be closed manually.

    thanks once again for your kind help

  15. #15
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 3
    Last Post: 08-05-2019, 02:41 PM
  2. Replies: 3
    Last Post: 08-01-2018, 07:47 AM
  3. Replies: 2
    Last Post: 08-15-2016, 02:47 PM
  4. Replies: 4
    Last Post: 12-30-2013, 05:51 PM
  5. vba code for regression analysis P value output
    By Frangipani in forum Programming
    Replies: 0
    Last Post: 02-04-2009, 06:26 AM

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