Page 1 of 3 123 LastLast
Results 1 to 15 of 43
  1. #1
    hinchi1 is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2017
    Posts
    181

    Filtered records

    I have a form which is used to create reports. if i don't filter the records on the form using a textbox to use keyword search. the report button will happily output a report of all the records in Word,PDF and excel. however, if i filter the records and the records that have been filtered exceed 495 records i cannot get a report to be outputted. any thoughts please.



    code for full report:
    Private Sub cmdPreviewReport_Click()
    On Error GoTo cmdPreviewReport_Click_Err
    Dim oApp As Object
    Dim oDoc As Object
    Dim sTmpltName As String


    'Dim AppWord As Application
    'Dim Doc As Documents
    'Dim NameOfDocument


    ' john's original code:
    'DoCmd.OutputTo acOutputReport, "rptBuildings", "PDFFormat(*.pdf)", "", True, "", 0, acExportQualityPrint


    ' nic meddling from here
    'NameOfDocument = "arse"


    'case statement here for pdf word or excel


    Select Case frmReportFormat.Value
    Case 1
    DoCmd.OutputTo acOutputReport, "rptBuildings", "PDFFormat(*.pdf)", "", True, "", 0, acExportQualityPrint
    Case 2
    DoCmd.OutputTo acOutputReport, "rptBuildings", "RichTextFormat(*.rtf)", "", True, "", 0, acExportQualityPrint
    Case Else
    DoCmd.OutputTo acOutputReport, "rptBuildings", "Excel97-Excel2003Workbook(*.xls)", "", True, "", 0, acExportQualityPrint
    End Select


    ' to here


    cmdPreviewReport_Click_Exit:
    Exit Sub


    cmdPreviewReport_Click_Err:
    'MsgBox Error$
    'Resume cmdPreviewReport_Click_Exit


    End Sub

    Code for filtered report:
    Private Sub CmdViewSelection_Click()
    On Error GoTo CmdViewSelection_Click_Err
    Dim strWhere As String
    Dim ctl As Control
    Dim varItem As Variant


    'make sure a selection has been made
    If Me.SearchResults_Multi.ItemsSelected.Count = 0 Then
    MsgBox "At Least 1 Record Must Be Selected!!", vbInformation, "Record Selection Required"
    Exit Sub
    End If


    'add selected values to string
    Set ctl = Me.SearchResults_Multi
    For Each varItem In ctl.ItemsSelected
    strWhere = strWhere & ctl.ItemData(varItem) & ","
    'Use this line if your value is text
    'strWhere = strWhere & "'" & ctl.ItemData(varItem) & "',"
    Next varItem
    'trim trailing comma
    strWhere = Left(strWhere, Len(strWhere) - 1)
    DoCmd.OpenReport "rptPartBuildings", acViewReport, , "RoomID IN(" & strWhere & ")"




    Select Case frmReportFormat.Value
    Case 1
    DoCmd.OutputTo acOutputReport, "rptPartBuildings", "PDFFormat(*.pdf)", "", True, "", 0, acExportQualityPrint
    Case 2
    DoCmd.OutputTo acOutputReport, "rptPartBuildings", "RichTextFormat(*.rtf)", "", True, "", 0, acExportQualityPrint
    Case Else
    DoCmd.OutputTo acOutputReport, "rptPartBuildings", "Excel97-Excel2003Workbook(*.xls)", "", True, "", 0, acExportQualityPrint
    End Select


    'open the report, restricted to the selected items
    'DoCmd.OpenReport "rptBuildings", acPreview, , "RoomID IN(" & strWhere & ")"
    'DoCmd.OpenReport "rptPartBuildings", acViewReport, , "RoomID IN(" & strWhere & ")"


    'DoCmd.OutputTo acOutputReport, "rptBuildings", "PDFFormat(*.pdf)", "", True, "", 0, acExportQualityPrint
    'DoCmd.SelectObject acForm, "frmBuildingSearch"
    'DoCmd.Close
    DoCmd.SelectObject acReport, "rptPartBuildings"
    DoCmd.Close
    CmdViewSelection_Click_Exit:
    Exit Sub


    CmdViewSelection_Click_Err:
    End Sub
    Attached Thumbnails Attached Thumbnails Report Form.PNG  

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Please post lengthy code between CODE tags to retain indentation and readability.

    You use textbox and combobox to filter the listbox then multi-select listbox is used to build filter criteria for report? RoomID is a text field?

    Could be the WHERE CONDITION string is too long. Access does have limits. One is a limit of 255 characters in a query parameter and since the WHERE CONDITION argument is equivalent to the WHERE CLAUSE of query, the same limit may apply.

    I did a test with an IN parameter array that had a trailing comma and it still opened filtered report. Tells me that possibly Access is truncating the string.

    Is user manually selecting hundreds of records in the listbox?
    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
    Join Date
    Apr 2017
    Posts
    1,681
    Maybe instead of collecting data for filter condition into listbox, collect them into some dummy table. Whenever you start selecting rooms you delete all entries from this table, and then add new ones. The source query for report will then be something like
    SELECT ... WHERE RoomID IN (SELECT RoomID FROM DummyTable)
    You also can try
    DoCmd.OpenReport "rptPartBuildings", acViewReport, , "RoomID IN(SELECT RoomID FROM DummyTable)"

  4. #4
    hinchi1 is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2017
    Posts
    181
    Thanks for your replies. The combobox is a separate filter to the list. Sorry I should have made that more clear. Not sure how you mean create a dummy table so any examples will be greatly appreciated. Also, how do I overcome the truncating of the string. I am still new to Access and learning all the time. Thanks again for your input.

  5. #5
    hinchi1 is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2017
    Posts
    181
    I missed part of your replies. The user filters the list by keywords and then selects the filtered results by clicking on the Select All button. Hope this makes sense.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    So did you understand response in post 2? The WHERE string is too long. The only way to overcome is to have a shorter string. Why not use the 'keywords' to filter the report?
    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.

  7. #7
    hinchi1 is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2017
    Posts
    181
    To be honest no I didn't. No idea how to implement this code or what was meant by using a dummy table, sorry.

  8. #8
    hinchi1 is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2017
    Posts
    181
    I do use the keyword to filter the listbox, but don't know how to shorten the search string.

  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,931
    Do the listbox and the report have the same fields, basically the same recordsource? Apply the same filter criteria to the report as you do for the listbox.
    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
    hinchi1 is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2017
    Posts
    181
    Thanks for your reply. I will check later but I am sure they do. If so, how do I apply the same filter to the report?

  11. #11
    hinchi1 is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2017
    Posts
    181

    Filtered records

    Quote Originally Posted by June7 View Post
    Do the listbox and the report have the same fields, basically the same recordsource? Apply the same filter criteria to the report as you do for the listbox.
    the rowsource of the list box is qryRoomInformation and the record source of the report is qryRoomInformation. I am open to all options to reslove this as i have 4 other forms holding diffrernt data but have a similar filter set up. Thanks again.

  12. #12
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    How are you filtering the listbox? Post the RowSource SQL statement.
    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.

  13. #13
    hinchi1 is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2017
    Posts
    181

    Filtered records

    Quote Originally Posted by June7 View Post
    How are you filtering the listbox? Post the RowSource SQL statement.
    Hi, below is the SQL from the query builder. As i type in the textbox the listbox filters out. the keywords i have setup are: RoomNumber,Campusnmae, BuildingName, etc. The OnChange event of the textbox is:

    If SearchFor_Multi.Text = "" Then
    CmdViewSelection.Enabled = False
    cmdPreviewReport.Enabled = True
    Else
    CmdViewSelection.Enabled = True
    cmdPreviewReport.Enabled = False
    End If


    Me.SearchResults_Multi = Me.SearchResults_Multi.ItemData(0)
    'Me.SearchResults.SetFocus
    'DoCmd.Requery "SearchResults_Multi"
    Me.SearchResults_Multi.Requery

    SQL From Query Builder

    SELECT qryRoomInformation.RoomID, qryRoomInformation.CampusNames, qryRoomInformation.BuildingName, qryRoomInformation.RoomNumber, qryRoomInformation.FloorID, qryRoomInformation.Floor, qryRoomInformation.SquareFootage, qryRoomInformation.BuildingID, qryRoomInformation.TypeID, qryRoomInformation.ActivityID, qryRoomInformation.CampusID, qryRoomInformation.UsedByID, qryRoomInformation.FrequencySpaceLevelsWeek, qryRoomInformation.HoursAvailableWeek, qryRoomInformation.FrequencyCalculation, qryRoomInformation.AvgPeoplePerHour, qryRoomInformation.MaxPeoplePerHour, qryRoomInformation.OccupancyCalc, qryRoomInformation.SpaceUtilisation, qryRoomInformation.RoomActivity, qryRoomInformation.RoomType, qryRoomInformation.WorkType
    FROM qryRoomInformation
    WHERE ((([qryRoomInformation]![CampusNames] & [qryRoomInformation]![BuildingName] & [qryRoomInformation]![RoomNumber] & [qryRoomInformation]![RoomActivity] & [qryRoomInformation]![RoomType] & [qryRoomInformation]![WorkType]) Like "*" & [forms]![frmBuildingSearch]![SearchFor].[Text] & "*"))
    ORDER BY qryRoomInformation.RoomNumber;

  14. #14
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    I never use dynamic parameterized queries but you could try that same WHERE clause in the report recordsource.

    User is supposed to enter only one value in the textbox?
    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.

  15. #15
    hinchi1 is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2017
    Posts
    181
    Thanks for the reply but you clearly have a better understanding than I do as I really don't know how to do this. But will keep looking. How would putting the where clause in the report recordsource help?

Page 1 of 3 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. filtered subform unshown records when choose another brand
    By georgesobhyy@gmail.com in forum Forms
    Replies: 6
    Last Post: 09-19-2016, 07:32 AM
  2. Dcount records from a filtered form
    By charly.csh in forum Access
    Replies: 6
    Last Post: 11-20-2014, 01:14 PM
  3. How to get count of filtered records
    By DBDave in forum Queries
    Replies: 2
    Last Post: 11-03-2014, 02:07 PM
  4. Exporting Pivot Table to Excell - only want filtered records
    By Jennifer227 in forum Import/Export Data
    Replies: 1
    Last Post: 04-01-2011, 03:10 PM
  5. Open form to filtered records
    By ducecoop in forum Access
    Replies: 3
    Last Post: 10-22-2010, 10:53 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