Avatar of stevid
stevid
 asked on

How to test a Control on a Access Report

i have an access form which has a checkbox that can be ticked or not labeled discount

If i click Discount on the form a discount box appears and allows the user to enter a discount value,

Now i have a report that displays the invoice but i only want the discount box to show on the report if dicount has been ticked in the form already,

How do i test if for this particular record discount has been ticked and subsequently make the discount box appear and change the font colour,

Any ideas??

Thanks,
Microsoft AccessDatabases

Avatar of undefined
Last Comment
stevid

8/22/2022 - Mon
dqmq

When the form applies the discount, then there must be some indicator in the underlying table(s).  Those indicators (discount%, perhaps?) need to be passed to the report.  Probably the easiest way is to add a discount field to the form's record source.   Conditional formatting of the report based on a column in the Record Source is trivial.
Jeffrey Coachman

Try something like this perhaps:

If me.DiscountChecboxControlField=True Then
   Me.txtDiscountAmount.visble=True
ElseIf me.DiscountChecboxControlField=False Then
   Me.txtDiscountAmount.visble=False
End if

<make the discount box appear and change the font colour,>
I'm confused, if the box is not visible, the font color is irrelevant...

Perhaps you should list the *exact* field names and control names of all the objects involved please?
(So we know if you are referring to the discount check "Box" or the Discount amount Text"Box")

In any event, you can select the control in design view, and click "Conditional" to conditionally format the font based on a condition.

JeffCoachman
Jeffrey Coachman

...Oh, ...my code would go on the Format event of the Detail Section.

Then the report must be opened in "Print Preview" specifically.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
stevid

ASKER
yes i have a simple tick box, discount

If you tick it the discount boxs appear and if its false they stay hidden

This tick box value is stored in the underlying tables, I have it passed to the report also,

I have been trying to use the onload event for the form to test the control and then usinf IF statements to say display or not but no good
stevid

ASKER
I need this to also work if i print or just display the form

stevid

ASKER
Tick Box  = [apply discount]
Text Box i want to show and hide = [txtTotalIncDis]
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
stevid

ASKER
Here is the code i have,

If Me.Apply_Discount.Value = True Then
    Me.txtTotalIncDis.Visible = True
Else
    Me.txtTotalIncDis.Visible = False
End If


Cant get it to work though, I reckon its to do with what event is generating it
SOLUTION
dqmq

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Jeffrey Coachman

You'll have to be a bit more specific when you say:
"Cant get it to work though,"
;-)

...And try to avoid spaces in your object names.
The "_" that vba inserts is a generic character it uses for any character it does not like...

(See here for notes on standard naming conventions:
http://www.xoc.net/standards/rvbanc.asp
http://en.wikipedia.org/wiki/Leszynski_naming_convention)


So in the format event of the detail section, it would look something like this:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

    If Me.chkApplyDiscount.Value = True Then
        Me.txtTotalIncDis.Visible = True
    Else
        Me.txtTotalIncDis.Visible = False
    End If

End sub


Finally, remember you *Must* Open the report in "Print Preview" explicitly, to see this work.


;-)


JeffCoachman
stevid

ASKER
Any ideas how i can get the above to work when i open it in normal view or print preview???

Thanks,
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER CERTIFIED SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
stevid

ASKER
No its a report alright,

I have it all working on the form part fine??

stevid

ASKER
Sorry was not a question above,

I have the form set up and the Discount Box appear and dissapear as i want,

I now want this to work on the Report for the form,
dqmq

Can you post the database.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
stevid

ASKER
not really,

It contains a lot of confidentail info and is based on a back end also,

I could export the form and report in question but it is based on back end tables so not sure how well that would work??

Jeffrey Coachman

<No its a report alright,>

Ok, this was confusing:
<How to test a Control on a Access Report>
then...
<i have an access form which...>

So again, this code should work on the Detail_Format event.

I'll back out now, I am sure dqmq can handle it from here...
dqmq

Sure, export the report, and if possible, copy the report's recordsource into a make table query and give us a few rows of actual data.   You can change names and places, etc. to protect the innocent.  
Your help has saved me hundreds of hours of internet surfing.
fblack61
stevid

ASKER
Ok have changed it all around and now just have a permanent special pricing box so everyone gets a special price :-)