Results 1 to 8 of 8
  1. #1
    gemadan96 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2012
    Posts
    110

    Filtered Report from filtered datasheet form

    I have a form users use to select criteria for opening a datasheet form of the filtered data. I would like to have a button on the form of filtered data to produce a report of that filtered data. I'm trying to figure out who to pass on the where condition used to open the form to the report.

    There are over 100,000 records in the table being used for the form and the report. The table itself is linked to a SQL server. The users will use the first form to filter the data by date range, category, and facility. Now I just need to make it so they can generate a report for printing or saving as a PDF.

  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
    Options:

    1. dynamic parameterized query that references form controls for input, review http://datapigtechnologies.com/flash...mtoreport.html

    2. VBA to construct filter criteria string, review http://allenbrowne.com/ser-62code.html
    Instead of setting the Filter property, pass the string with OpenReport
    DoCmd.OpenReport "report name", , , strWHERE
    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
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Maybe something like this

    Code:
    Dim strWhere As String
    strWhere = ""
    if me.filteron = true then
    strWhere = Me.Filter
    End If
    Debug.Print strWhere
    DoCmd.OpenReport "ReportName", acViewPreview, , strWhere, acHidden
    DoCmd.SelectObject acReport, "ReportName", False
    DoCmd.OutputTo acOutputReport, "rReportName, acFormatPDF
    DoCmd.Close acReport, "ReportName"

  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,929
    DOH! Of course! If you want the exact same filter criteria that was applied to the form, just use its Filter property to grab the criteria string. Excellent!
    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
    gemadan96 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2012
    Posts
    110
    Thanks. Works great. Just had to modify to suit my needs...

    Dim strWhere As String
    strWhere = ""
    If Me.FilterOn = True Then
    strWhere = Me.Filter
    End If
    Debug.Print strWhere
    DoCmd.OpenReport "StudyList", acViewPreview, , strWhere, acHidden
    DoCmd.SelectObject acReport, "StudyList", False
    DoCmd.OutputTo acOutputReport, "StudyList", acFormatPDF
    DoCmd.Close acReport, "StudyList"
    End Sub

    The only issue is if I cancel on the OutputTo window I get a MS Visual Basic error: Runtime error '2501': The OutputTo action was canceled. It then wants me to click end or debug. If I select debug it highlights the DoCmd.OutputTo line.

    Any suggestions to eliminate/resolve are appreciated.

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    You can do an 'on error resume next' or build a custom error trap to handle the error number '2501' for cancel.

    If it is the last code within the sub probably just an 'on error resume next'

  7. #7
    gemadan96 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2012
    Posts
    110
    That did it. Thanks.

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    You should also be able to attach that same PDF directly to an email without saving it. Just replace the DoCmd.OutputTo acOutputReport, "StudyList", acFormatPDF

    with


    .
    Code:
    DoCmd.SendObject acReport, "rptNameofReport", acFormatPDF, "ToEmailAddress", "CcEmailAddress", "BccEmailAddress", "Email Address Subject Line", "Text to Include within Email Body", True
    The True at the very end will pause to allow the user to view and edit the email where False will send it without any user interaction.

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

Similar Threads

  1. Replies: 2
    Last Post: 07-28-2014, 01:15 PM
  2. Replies: 3
    Last Post: 11-06-2012, 03:25 PM
  3. Report based on Query but filtered by form
    By michel_annie22 in forum Reports
    Replies: 1
    Last Post: 10-23-2012, 10:40 PM
  4. Select Report fields based on filtered form
    By brpathirana in forum Reports
    Replies: 0
    Last Post: 07-29-2012, 04:23 AM
  5. Report based of filtered data from a form
    By Fabdav in forum Reports
    Replies: 1
    Last Post: 09-15-2011, 05:28 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