Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    tonygg is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    115

    Passing the contents of a listbox from a form into a report

    Hi. I have a listbox populated with calculated data. I would like to display it on a report but cant seem to reference it from the report.

    I have a series of textboxes on the form that I can easily reference from the report by setting the control source of the field in the report to:

    =Forms![Form Name]![TextBox Name]

    These appear on the report once it is launched from the form using the command:

    DoCmd.OpenReport "Report Name", acViewPreview

    If I use the same construct on a listbox object in the report it does not work. I guess I am using the wrong syntax when setting the control source:

    =Forms![Form Name]!
    [Listbox Name]

    Please could someone help me get the syntax correct.



    Many thanks

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    That should work, unless the listbox is multiselect (and even if single select, an item would need to be selected). Also, that would return the bound column, if different than the displayed column(s).
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    tonygg is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    115
    Sorry but I am being a bit slow.

    I created the listbox in the report and called the report from the form. All other text boxes populated but this listbox remained blank.

    The source listbox has 22 columns and a variable number of columns (depends on what is selected in the form). I ideally only want/need to display the 1st 5 columns.

    I am not familiar with multi select and single select. Please could I trouble you to let me know where I check these values (on the report or form or both and where in the field properties?)

    Many thanks

    Tony

  4. #4
    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 mean a variable number of rows (records)? When you say you have the listbox on the report, are you wanting it to display the same records as displayed on the form? If so, you'd need to give it the same row source as the one on the form.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    tonygg is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    115
    Sorry to be clear the listbox contains calculated data and user selections that cannot be recreated by a query.

    It it has a fixed number of fields but there could be between 1 and 30 rows in the listbox.

    i just need to display the first 5 columns of the listbox on the report.

    thanks

  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
    Again, if you want the listbox on the report to display the same records as the listbox on the form, they need to have the same row source. Perhaps this will work in the format event of the section of the report containing the listbox:

    Me.ListboxName.RowSource = Forms!FormName.ListboxName.RowSource
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    tonygg is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    115
    Thank you. That gets the data over to the report if I open the report independently (after running the form). However when I try to open the report from the form using:

    DoCmd.OpenReport "LUCY BARCLAY RECON REPORT", acViewPreview

    I get the error: "You cant set rowsource property in print preview or after printing has started."

    Any suggestions to get around this would be gratefully received.

    Thanks

    Tony

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,899
    What exactly is the SQL statement for the listbox RowSource property?
    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.

  9. #9
    tonygg is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    115
    It is populated from a value list not an sql query. Thanks

  10. #10
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,899
    Therein lies the issue.

    I don't even see how the report opened manually could work, unless maybe it is opened in Report or Layout view.

    Listboxes are not even intended to be used on reports. I have done that only once.
    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.

  11. #11
    tonygg is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    115
    Ok but it does work if opened in report view with all the data sourced from the form using the method pbaldy helpfully gave me (above) and can be printed by using a DoCmd.PrintOut command in the report itself.

    The only issue I have is that I cant launch it from the form it references. If anyone can help with this issue of launching from the form then I would be grateful.

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Can you post the db here?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  13. #13
    tonygg is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    115
    OK. This link:

    https://onedrive.live.com/redir.aspx...int=file%2cmdb

    gets you the DB (Its too big to attach here as it is from a system - I have just added some functionality). It has 1 form and 1 Report and the full set of tables (I have removed the rest of the forms and reports).

    In order to correctly run the report you need to open the form and you will see at the top of the form two combo boxes (Batch from and batch To). You need to select a batch number from each of the drop down lists. I suggest selecting batch 1 (from) and batch 5 (to). You will see a button next to these called "Get Batches". Press this button and the form will be populated. Once done if you open the report you will see it is correctly populated with the same data (or a cut down version of the data).

    What I would really like to do is have a button on the form to launch the report and print it. I have tried but it crashes the system with the errors in the above posts

    Hope it helps

    Thanks a lot

    Tony

  14. #14
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,899
    Maybe Paul can help. I can't download from file share sites at this location and if the file is large won't be able to at home on my slow internet.

    How can a db with 1 form and 1 report be too large? Did you remove most data, Compact & Repair, zip (2MB zip allowed)?

    What does 'from a system' mean?
    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
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Moving the code to the report open event seems to work; it opens in preview mode without error anyway.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Passing A Date Range From Form To Report
    By JeffGeorge in forum Reports
    Replies: 3
    Last Post: 03-11-2014, 12:50 PM
  2. Passing data betwen forms listbox help
    By PoorBoy in forum Forms
    Replies: 1
    Last Post: 03-07-2013, 11:35 PM
  3. passing openArg to a listbox on other form
    By focosi in forum Access
    Replies: 7
    Last Post: 08-12-2011, 04:27 PM
  4. Replies: 5
    Last Post: 04-03-2011, 10:24 PM
  5. Replies: 1
    Last Post: 03-24-2010, 08:42 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