Results 1 to 4 of 4
  1. #1
    mreniff is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2020
    Posts
    41

    Print preview Reports from ListBox values

    I have listbox (lstBxFlightpaths on frmGroupREeport) that lists assorted reports to view. I macro in AfterUpdate property open selected report in ReportView. I want to use this list to allow end user to print single or multiple reports. The list box Mutli select property is set to Extended.



    Upon clicking on a report name in the list box, the selected report(s) open in report view.

    I found this code online and tried to substitute my object names. I select one report name and fails at strWhere clause run time error 5. Invalid procedure call or argument.

    I certainly do not need to use this code. I am open for any suggestions.

    Code:
    Private Sub lstBxFlightpaths_AfterUpdate()
    
    Dim strWhere As String
    
    
    Set Ctl = Me.lstBxFlightpaths 'listbox wth report names
    Dim Varitem As Variant ' remed out for now ' If Me.Machine.ItemsSelected.Count = 0 Then 'MsgBox "Must Select at least One Report" 'Exit Sub 'End If Set Ctl = Me.lstBxFlightpaths For Each Varitem In Ctl.ItemsSelected 'report selected from list strWhere = strWhere & "'" & Ctl.ItemData(Varitem) & "'," Next Varitem strWhere = Left(strWhere, Len(strWhere) - 1) 'fails here with run time error 5. Invalid procedure call or argument. DoCmd.OpenReport "Single Flightpath Report", acViewReport, , "Report No In (" & strWhere & ")", acWindowNormal End Sub

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    if len =0 it will fail.
    put a break point on this line, then when it stops ,hoover the cursor over strWhere to see the value.

  3. #3
    mreniff is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2020
    Posts
    41
    Quote Originally Posted by ranman256 View Post
    if len =0 it will fail.
    put a break point on this line, then when it stops ,hoover the cursor over strWhere to see the value.
    The value is ""
    Click image for larger version. 

Name:	strwhere value.JPG 
Views:	11 
Size:	23.2 KB 
ID:	41837

    I remed out 'strWhere = Left(strWhere, Len(strWhere) - 1) and the last section of "Report No In (" & strWhere & ")", acWindowNormal
    The report immediately open, as it did before, but the listbox will not allow for multi-selection of report.

    With Multselect set to Simple or Extended, the reports are opening without any data.

  4. #4
    mreniff is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2020
    Posts
    41

    REport SQL statment

    Code:
    SELECT DISTINCT Students.ID AS StudentID, Sessions.ID AS SessionID, Students.FlightPath, Students.PreProf, Students.HC, Students.Path, Students.USP, Students.SSN, Students.First, Students.Last, [Group Advising].locationName AS locname, [Group Advising].Time AS StartTime, Students.PIN, Students.Major, Students.Class, Sessions.Session, Sessions.Session AS SessionName
    
    FROM (Students LEFT JOIN Sessions ON Students.Session = Sessions.ID) LEFT JOIN [Group Advising] ON Students.GroupAdvisingSessionID = [Group Advising].GroupAdvisingRecordID
    
    WHERE (((Sessions.ID)=[Forms]![ReportsSession]![SessionCombo]) AND ((Students.FlightPath)=[Forms]![frmGroupReports]![lstBxFlightpaths]));

    Quote Originally Posted by mreniff View Post
    The value is ""
    Click image for larger version. 

Name:	strwhere value.JPG 
Views:	11 
Size:	23.2 KB 
ID:	41837

    I remed out 'strWhere = Left(strWhere, Len(strWhere) - 1) and the last section of "Report No In (" & strWhere & ")", acWindowNormal
    The report immediately open, as it did before, but the listbox will not allow for multi-selection of report.

    With Multselect set to Simple or Extended, the reports are opening without any data.

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

Similar Threads

  1. Replies: 5
    Last Post: 09-16-2019, 01:12 AM
  2. Replies: 5
    Last Post: 07-29-2014, 01:05 PM
  3. Replies: 6
    Last Post: 03-01-2014, 07:07 AM
  4. Runtime Print Preview Toolbar on reports
    By Ruegen in forum Access
    Replies: 7
    Last Post: 10-08-2013, 08:15 PM
  5. Replies: 11
    Last Post: 10-06-2010, 12:19 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