I tried to do this but I am not getting
the syntax correctly. Could you show
me some code please? I am leaving the
form open when the report launches and
I am using Access 2003. I am not very
familiar with using the OpenArgs
function. Please show me! I want to
open [cboQueryList].Value.* as the
record source...
I assume that you place your DoCmd.OpenReport statement in the Click event
of a CommandButton, so it will be executed when you click the Command
Button. You should test the Controls to make sure something has been
selected in each Combo Box, which testing is included in the code below:
Dim stDocName As String
Dim strOpenArgs As String
If Not IsNull(Me.cboReportList) Then
stDocName = Me.cboReportList
If Not IsNull(Me.cboQueryList) Then
strOpenArgs = Me.cboQueryList
DoCmd.OpenReport stDocName, acPreview, , , , strOpenArgs
Else
MsgBox "Query must be specified, please try again."
End If
MsgBox "Report must be specified, please try again."
End If
In addition, in the Open event of the Report, the following VBA code will
use the name of the Query, passed in OpenArgs, to reset the RecordSource of
the Report. If you have a great deal of data, you may see some evidence that
this approach is more efficient than using the WhereCondition or the Filter
arguments of DoCmd.OpenReport.
Generally, Report contents are so closely bound to the RecordSource that the
only thing that can differ is to select a different subset of records from a
larger source. If that is true with your report, as it likely is, consider
reading about and using the WhereCondition or Filter arguments instead of
making separate Queries. In my test database, where I used the Northwind.MDB
Category table as my test data, I could just as, or more, easily selected a
Category in my Combo box and constructed a WhereCondition argument that
would have worked equally as well.
Please respond - I have posted three
different questions, and I get great
early response with zero follow up.
Thanks in advance.
All the answers in these newsgroups, with extremely rare exceptions, are
from volunteers. And, I expect that most have schedules similar to mine --
participation in newsgroups will vary from day to day, because other
activities may take priority. In fact, from the time I began this response
and the time I finished it, I had a five-hour interruption.
Larry Linson
Microsoft Access MVP