Chrystal,
I'll read tomorrow ("I have a baby 1/2day off")

I tried the code, but before to answer your question:
how are you selecting Report A or Report B? From a list box
Are the fieldnames the same in both reports that would be using the
criteria? yes (I'll doublechecke)
So here is the code:
Private Sub cmdOpenReport_Click()
'tell Access you are going to create a variable
Dim mFilter As Variant
Dim mReportname As String
'initialize the variable
mFilter = Null
If Me.grpFilterOptions = 1 Then
End If
If Not IsNull(Me.[Beginning Visit Date]) Then
mFilter = (mFilter + " AND ") _
& "[DateofTest]>= #" & Me.[Beginning Visit Date] & "#"
End If
If Not IsNull(Me.[Ending Visit Date]) Then
mFilter = (mFilter + " AND ") _
& "[DateofTest] <= #" & Me.[Ending Visit Date] & "#"
End If
If Not IsNull(Me.ChooseStudy) Then
mFilter = (mFilter + " AND ") _
& "[StudyID]= " & Me.ChooseStudy
End If
If something = True Then
mReportname = "ReportDipstick"
Else
mReportname = "ReportPregTest"
End If
If Not IsNull(mFilter) Then
DoCmd.OpenReport mReportname, acViewPreview, , mFilter
Else
DoCmd.OpenReport mReportname, acViewPreview
End If
End Sub
Good night!
:
Hi Sylvie,
thank you and you're welcome
the combo should not be in your option group -- just make it apply if it
is filled out -- if not, then ignore it
~~
"But if I choose ReportB, it shows me ReportA. "
that won't happen if you change the code

Yes, this is the statement
that is opening whatever report is specified:
you could use a variable for the report name instead of literally
putting a name on this line:
DoCmd.OpenReport "Your Report Name", acViewPreview, , mfilter
It is customary to declare variables at the top of a procedure (after
the statement to set up the error handler)
'~~~~~~~~~~~~~~~
Dim mReportname as string
'~~~~~~~~~~~~~~~
then, after the criteria is processed:
'~~~~~~~~~~~~~~~
if something = true then
mReportname = "Report A"
else
mReportname = "Report B"
end if
if not IsNull(mfilter) then
DoCmd.OpenReport mReportname, acViewPreview, , mfilter
else
DoCmd.OpenReport mReportname, acViewPreview
endif
'~~~~~~~~~~~~~~~
how are you selecting Report A or Report B?
Are the fieldnames the same in both reports that would be using the
criteria?
oops, I goofed on the statement ADD the Class to the filter
anyway...Replace what I gave you with this:
'~~~~~~~~~~~~~~~
If not IsNull(me.class_controlname ) Then
mFilter = (mFilter + " AND ") _
& "[ClassID]= " & me.class_controlname
end if
'~~~~~~~~~~~~~~~
WHERE
class_controlname is the Name property of your combobox to pick a Class
-- open the property sheet, click on the combo, select the ALL tab in
the Properties window and see what is in the NAME property. If it is
ambiguous, like combo143, change it to something that makes sense, like
cboClassID
and then, so the criteria can make sure that ClassID is ON the report
even if the Visible property is No
~~~
once you change your procedure, compile it. Look at each line. If
anything does not make sense, post the entire procedure as you have
modified it, then ask about specific lines and we will help you
understand them
go back to the first post I made to this thread -- print it out and read
it a few times as it has more comments
you can do this!
Warm Regards,
Crystal
remote programming and training
Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace
*

have an awesome day

*
Sylvie wrote:
Thanks for your patience Chrystal, you are very good on explain it!!
I tried this code before and I did not work. When I choose(from my list
box) the ReportA and enter the dates (option group) it works great. But if I
choose ReportB, it shows me ReportA. I think somehow on the code line:
DoCmd.OpenReport "ReportName", acViewPreview, , mfilter
I need to not put the report name but let be the one the user choose (out of
15 or so). I do not if it is possible. As for the class I have a combo inside
group and did not work either. IF is a combo, how can I enter classfield name
and control name? On the Row Source? I have: SELECT Class.ClassID,
Class.ClassName FROM Class ORDER BY [ClassName];
mfilter = "[ClassFieldname]= '" & me.class_controlname & "'"
Maybe if I take the combo out of the option group. Any ideas?
Have a great day =^..^=
:
Hi Sylvie,
what I gave you builds the filter string
what you are doing now will just get more complicated as you decide you
want other criteria options. It is a better plan to build the filter
string in code then launch the report using the WHERE condition argument
to OpenReport -- then end result is the same: the report is filtered.
the advantage of building it in code is that you can ignore criteria
that is not filled and you don't end up with a long equation in the
report filter property.
"I am very new to coding"
Once you do it, it is not hard ... don't let code scare you off! anyone
who can put a complex equation like you did in the report filter
certainly has a logical mind to write VBA code
read this:
Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace
~~~~~~~~~
turn on the property sheet in the design view of your [View
Reports] form
make a command button
Give it a good name, like --> cmd_RptWhatever
(best not to use spaces in names)
Caption --> Open Report
(you can put what you like as this is not too descriptive)
with the command button selected:
click in the 'On Click' event in the property sheet (Events tab).
Notice the the drop-down arrow on the right -- drop list and choose -->
[Event Procedure]
click the builder button [...] to the right to write the code
paste the code in below, substitute the right control and field names
compile and test <smile>
here is some code you can start with (don't forget to remove the filter
from your report)
'~~~~~~~~~~~~~~~~~~~~~~~~~~
'tell Access you are going to create a variable
dim mFilter as variant
'initialize the variable
mFilter = null
if me.grpFilterOptions = 1 then
If not IsNull(me.[Beginning Visit Date]) Then
mFilter = (mFilter + " AND ") _
& "[DateofTest]>= #" & me.[Beginning Visit Date] & "#"
end if
If not IsNull(me.[Ending Visit Date] ) Then
mFilter = (mFilter + " AND ") _