Hide Field on Click

P

Pam

Hi,

I'm looking for a way to make a field either visible or not based on command
button selected. I've searched thru posts and have found visible with
conditional formatting- not quite what I want to do.

What I have is a quote with pricing on it. I want to click on a command
button "Quote With Pricing" and have all the pricing printed on report. If
I click other button "Quote Without Pricing", I want to use the same report
and not have the pricing printed.

Main Quote is "rQuote"
Subreport is "rQuotePartsSubreport"
Fields to hide/unhide are "Price" and "PriceExtension"

It sounds easy enough, but not sure how to go about it.

Any help is greatly appreciated!
Thanks,
Pam
 
J

Jeff Boyce

Pam

I'm not clear, from your description, where you would expect the "command
buttons" to be.

Were this my project, I'd create a form to "order" the report(s). I'd use a
single command button, and an option group to allow a choice between "with"
and "without".

Then, in the report, as it formatted the section with this info, I'd have it
make the control visible or not, depending on which option button was
pressed back on the form. I'd do this by pointing back with something like:
If Forms!YourOrderForm!grpYourGroup =1 Then
Me!MyPrice.Visible = True
Else
Me!MyPrice.Visible = False
End If

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
K

Klatuu

You can't determine, from a report, whether a command button has been
selected. It would be much easier if you used an option group with two
toggle buttons. Using an option group requires no additional coding;
however, using one or more command buttons takes some coding. It is also
necessary that the form be open while the report is printing, because the
report will be looking at the option group on the form to know what to do.

For the Option group. Make one button's Caption "Without Pricing" and its
Option Value = 0. Make the other button "With Pricing" and an OptionValue =
-1.
When you click on the With Pricing button, the Option Group will return a
value of -1 (True) and when you click an Without Pricing, it will be 0
(False). The advantage over the command buttons is that command buttons
return no value, but an option group does. Yes, you could use the Tag
property of a command button, but in this case, you would have to check both
command buttons Tag property, as well as keep them correct with code.

Now we need a little code in the report. It should go in the On Print event
of the section of the report the controls you want to hide are in. It is as
simple as this:

Me.Price.Visible = Forms!MyFormName!MyOptionGroupName
Me.PriceExtension.Visible = Forms!MyFormName!MyOptionGroupName
 
P

Pam

Thanks both Jeff and Klatuu. I think I like your ideas much better. It
seems to be a smoother procedure. I will work on it.
 
K

Klatuu

Actually, our ideas or the same. Jeff does have a point, however, it may be
that you need to use the On Format event rather than the On Print event. If
the Print event doesn't work, move the code to the Format event.

Without testing it myself, I can't remember which way is correct.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top