Results 1 to 3 of 3
  1. #1
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186

    Condition Where into a DoCmd.OpenReport

    Hi Everyone,

    Today I write asking your support on this

    I have this code to show a report and print this as pdf, but I want to use a criteria into the statement DoCmd.Output and I do not know how to do it. I highly appreciate your support

    ************************************************** ***************



    Dim stDocName As String
    Dim stLinkCriteria As String
    Dim stFileName As String


    stDocName = "Diagram_ABC"
    stLinkCriteria = "[ID]=" & "'" & Me.ID & "'"
    stFileName = CurrentProject.Path & "" & stDocName & Format(Date, "YYYYMMDD") & ".pdf" 'set the file name for the new PDF

    'IF I want to open I use this line below according to my criteria
    DoCmd.OpenReport stDocName, acViewNormal, , stLinkCriteria


    'I want to print the report as pdf and I am using this line, the issue is that I don't know how to insert the criteria as line here below


    'DoCmd.OutputTo acOutputReport, stDocName, acFormatPDF, stFileName, True



    'Somebody give a recommendation that I should modifiy the report to include the criteria into its record source and save it with another name
    'it is an awesone idea and works pretty good, the only concern is that I don't want to create a lot of double reports with this concept;


    'for me would be better to insert the criteria

    'any idea? Thanks!!!!





    MsgBox "Report to PDF", vbInformation, "Exporting to PDF"


    Exit_ImprimirPapelcmd_Click:
    Exit Sub


    Err_ImprimirPapelcmd_Click:
    MsgBox Err.Description


    Resume Exit_ImprimirPapelcmd_Click

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    put the criteria in the report Query, so theres no need for the param: stLinkCriteria

    then the report will be the same as the pdf.
    use a form to enter criteria, and the query uses it.

    (tho If its complex,you may need vb to help w the querydef,)
    but yours is simple... the sql is:
    where [id]=forms!fMyForm!ID

  3. #3
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    Docmd.OutputTo does not take a criteria (Where) parameter like Docmd.OpenReport.

    You could dynamically change the report's recordsource by manipulating the query's SQL statement (QueryDef) or you could do what is suggested here:
    https://social.msdn.microsoft.com/Fo...orum=accessdev

    Code:
    
    DoCmd.OpenReport stDocName, acViewPreview, , stLinkCriteria,acHidden 'open report in print preview hidden
    DoCmd.OutputTo acOutputReport, , acFormatPDF, stFileName, True 'create PDF from hidden active report - notice report name is empty
    Docmd.Close acReport,stDocName,acSaveNo
    Cheers,
    Vlad
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

Similar Threads

  1. Help with an OpenReport Where Condition
    By hehrerh in forum Reports
    Replies: 1
    Last Post: 06-29-2017, 08:56 AM
  2. DoCmd.OpenReport WHERE condition
    By bidbud68 in forum Programming
    Replies: 16
    Last Post: 10-19-2012, 05:31 AM
  3. Need help w/ docmd.openreport
    By jwill in forum Reports
    Replies: 3
    Last Post: 06-04-2012, 09:49 PM
  4. OpenReport WHERE Condition Not Working
    By altemir in forum Reports
    Replies: 1
    Last Post: 02-17-2012, 09:58 AM
  5. DoCmd OpenReport ... where condition with a Like
    By Grooz13 in forum Programming
    Replies: 4
    Last Post: 08-31-2010, 09:04 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