Unanswered: Selected record(s) from subform to report
Your help in the past has been valuable so I'm coming back to the well...
I have a search form (frmSearch) composed of listboxes in my database (which is attached here) that includes a subform (subSearch). When a user selects criteria in the listboxes and clicks the "Display" button, the matching records appear in the subform. I now want to be able to click the "Create Report" button on the subform to transfer only the matching files to the report (ResultsReport). I have a code in there that I have been trying to work with but to no avail. I think it is the way my objects are set up on the query. Any ideas? Much appreciated in advance. Cheers!
This is relatively simple to do. First off, we'll take the strSQL String variable and make it Public to all code modules within the database. To do this, we declare the strSQL variable in a code module located within the Modules section of your database. I named it "Main Module". Now the strSQL variable can supply its' contents to ALL code within the application.
We then remove the previous declaration of the strSQL variable located within the Display button's OnClick event (otherwise a error will occure). So far so good.
Now we go to the Create Button and in its' OnClick event, we add the strSQL variable in place of the OpenArgs argument within the Docmd.OpenReport statement. That all for this event.
Now, we travel over to the Report itself and within the OnOpen event of the Report form we add this line of code:
Me.RecordSource = Me.OpenArgs
That just about covers it. See the ReWorked database attached to this post.
Thanks for the help with the code. I kind of see what you did though I'm still learning this stuff. There is one problem however. When I click the "Create Report" button on the subSearch form I get a Compile error out of the code which I obviously don't understand. Any further help would be appreciated. Thanks again!
Although it works fine on my system, I did a little checking within the code and found something rather odd within the Create Report button code. I noticed that a parameter constant for the OpenReport function was in fact inconsistant with Access 2000. This is the acPreview parameter. It should be acViewPreview. Please, make the change in your code.
Other that that explained above, I see nothing wrong with the code.