I want to send the selected items from a multiselect list box to a report.... the code below will do this... but only after I close & reopen the report. How can I set [reports]![explanrpt]![plyolisttxt] to vplyo so that it will show immediately in Print Preview?? I'm sure this is simple, but I'm having a brain block. Any help?? Please?
Private Sub ExPlanPrintCmd_Click()
Dim frm As Form, ctl As Control, vPlyo As String
Dim varItm As Variant
Set frm = [Forms]![explanfrm]
Set ctl = [Forms]![explanfrm]![PlyoList]
For Each varItm In ctl.ItemsSelected
vPlyo = vPlyo & ctl.ItemData(varItm) & Chr(13) & Chr(10)
DoCmd.OpenReport "ExPlanRpt", acViewPreview
[Reports]![explanrpt]!plyolisttxt = vPlyo
Move the whole shebang to the on_open event of the report.
When you call DoCmd.OpenReport, anything after that statement is going to wait until the report is generated. Therefore it's impossible to assign dynamic values to the report in the onclick event of your form. However,by moving the code to the on_open event of the report and only calling DoCmd.OpenReport from your form, you will dynamically load your values every time the report is opened.
The only problem with this method is if you are NOT opening the report from the same form everytime. You'll get an error about "can't find such and such form" in such a case.