It's getting those darned quote marks right that are causing the problem
If your form contains a text box called RoofPlanLoc then that bit is fine.
if RoofPlanLoc is a text field then your code should read
DoCmd.OpenReport "rptMapRoofPlans", acPreview, , "[RoofPlanLoc] =""" &
Me.[sfrmClientBuildings].Form.[txtRoofPlanLoc] & """"
that's 3 quotemarks before the first & and 4 quotemarks after the last &
Make sure in Properties, by clicking on your subform in the Main form's
Design View, that it is actually called sfrmClientBuildings - it's name as a
control in a main form can be different from the name you see in the
database window.
Just one thing. txtRoofPlanLoc is actually a text box, isn't it? It's not a
combo box, is it? The reason I ask, is because the item which a combo shows
isn't always its value.
Evi
Thanks Evi for the input. My code now looks like this (my field is text):
Private Sub Option60_Click()
DoCmd.OpenReport "rptMapRoofPlans", acPreview, , "[RoofPlanLoc] =' " &
Me![sfrmClientBuildings]!Form![txtRoofPlanLoc] & " '"
End Sub
and still nothing is happening. Is the field supposed to be the name of
the
control, as in txtRoofPlanLoc, or is it the control source? Though I've
tried it both ways and either way there is no response.
Thanks, JIM
:
If you are using an Option Group to select the report, rather than a
single
option button, then the code is slightly different because it actually
loops
through an array, assigning a value to each one but assuming a single
option
button, your first piece of code won't work because it doesn't include
the
name of your report after
OpenReport.
Also, I'm a bit concerned about you having a / in your report name - I'm
not
sure if that will cause problems to Access because, like &, -, + and = ,
it
is an Operator. May I suggest that you remove this for now and replace
it
once everything else is working and see if it does no harm.
I'm going to assume that there is a control in the subform of your
current
form that contains the value for RoofPlanLoc which you want to filter by
clicking on the Option button in your main form.
I will also assume that RoofPlanLoc is a number (if it is text, the last
bit
of the code will be slightly different)
Your code can now read like this:
DoCmd.OpenReport "rptMapRoofPlans", acPreview,,"[RoofPlanLoc]=" &
Me.[sfrmClientBuildings].Form.[txtRoofPlanLoc]
Note the 2 commas after acPreview and the quote marks around the literal
part of the "Where" condition.
Evi
Thanks Evi for your input. I have a report that prints a Word
document,
the
file location is hard coded in a report subroutine. Instead of having
data
input person go to a report I thought I could just call the report
when
entering data on the form. The command button is on a subform and
when
clicked it does nothing at all.
If I run the report on its own it works.
Thanks, JIM
:
These codes are both printing reports, not Word Documents.
Evi
Hi, after researching, I think the best way to print a Word
document
from
a
form is with the following code behind an Option Button:
Private Sub Option60_Click()
DoCmd.OpenReport acViewNormal, qryWorkOrders, [RoofPlanLoc] =
Forms!frmWorkOrders![sfrmClientBuildings]!Form![txtRoofPlanLoc]
End Sub
or
Private Sub Option60_Click()
DoCmd.SelectObject acReport, "rptMap/RoofPlans", True
DoCmd.PrintOut
End Sub
But I can't get either to work. What am I missing?
Thanks, JIM