Results 1 to 14 of 14
  1. #1
    angie is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2013
    Posts
    232

    hiding a label in a report

    I am tryingto hide a label on a report if a field is $0.00, I tired the following but itis not working


    I have putit in the detail of the report where the field and label is in the eventformat.

    Private SubDetail_Format(Cancel As Integer, FormatCount As Integer)
    IfNz(Me.FinancedPrice, " ") = " " Then Me.Label163.Visible =False
    End If
    End Sub

    not sure what I am doing wrong. I am wanting it to hide three different labels but not sure what to do .

    the labels are label163 label 101 label 102 the field on the report is financedprice and the default value is $0.00

    Thank you

  2. #2
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    Try this to take care of nulls:
    Code:
    If Len(Me.FinancedPrice & vbnullstring) = 0 Then Me.Label163.Visible =False
    Another way:
    Code:
    If Nz(Me.FinancedPrice, 0) = 0 Then Me.Label163.Visible =False
    If the default value can be relied on to be zero and not null then
    Code:
    If Me.FinancedPrice= 0 Then Me.Label163.Visible =False
    Last edited by davegri; 04-08-2018 at 01:52 PM. Reason: add more

  3. #3
    angie is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2013
    Posts
    232
    I did thefollowing and it hide the label, but it hides it even if the amount in thefields is greater than 0
    I think Ineed a else code not sure

    Private SubReport_Load()
    IfNz(Me.FinancedPrice, 0) = 0 Then Me.Label163.Visible = False
    IfNz(Me.CashPrice, 0) = 0 Then Me.Label164.Visible = False
    IfNz(Me.EstPayments, 0) = 0 Then Me.Label91.Visible = False

    End Sub

  4. #4
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    OK, this code will explicitly set the property:

    Code:
    Private sub Report_Load()
    If Nz(Me.FinancedPrice, 0) = 0 Then 
        Me.Label163.Visible = False
    else 
        Me.Label163.visible = true
    endif
    If Nz(Me.CashPrice, 0) = 0 Then 
        Me.Label164.Visible = False
    else
        Me.Label164.Visible = true
    end if
    If Nz(Me.EstPayments, 0) = 0 Then 
        Me.Label91.Visible = False
    else
        Me.Label91.Visible = true
    End if
    End Sub
    If this doesn't work, then try putting the code in the Report_Open event instead.
    Last edited by davegri; 04-08-2018 at 04:01 PM. Reason: format

  5. #5
    angie is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2013
    Posts
    232
    it removed the label on true or false statement
    I tried on open and load event

  6. #6
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    First, I'm pretty sure a report is similar to a form in that the controls don't hold values in the Open event, so trying to reference a value On Open won't work.
    Second, a report is like a continuous form in that a control only really exists once, so if the logic satisfies the condition even once, all iterations of that control will be affected.
    A report does have a Detail Format event (which I believe only fires in Print Preview) but I still don't think the logic will affect only labels where a record satisfies the logic. Now the report Paint or Retreat events might work, but I can't remember if I've ever used either, so I don't know.

    You may have to resort to conditional formatting, which will require you to change the label to a textbox as labels don't accept cf.
    Last edited by Micron; 04-08-2018 at 05:00 PM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    angie is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2013
    Posts
    232
    Quote Originally Posted by Micron View Post
    First, I'm pretty sure a report is similar to a form in that the controls don't hold values in the Open event, so trying to reference a value On Open won't work.
    Second, a report is like a continuous form in that a control only really exists once, so if the logic satisfies the condition even once, all iterations of that control will be affected.
    A report does have a Detail Format event (which I believe only fires in Print Preview) but I still don't think the logic will affect only labels where a record satisfies the logic. Now the report Paint or Retreat events might work, but I can't remember if I've ever used either, so I don't know.

    You may have to resort to conditional formatting, which will require you to change the label to a textbox as labels don't accept cf.
    Could An event in the financedprice text box work? that if the amount is null than label is hidden but if there is an amount in the text box than label is visible. I could do the same for cashprice and estpayment

  8. #8
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    WRT my 2nd comment. I based that on a prior attempt which I couldn't get to work, so I wasn't just spouting off. In the meantime, I played around with cf, and did a little research which indicated what you're trying to do should work. Tried again, and all of a sudden it started working, so I have no idea what changes made that happen. If it's not working for you, then perhaps your test for the control value isn't quite right. Not sure what
    it removed the label on true or false statement
    means.

    If you want to post a zipped copy of the db (strip down the copy if it contains personal data) I'll take a look at it.
    EDIT:
    For my case, it seems that the detail section's On Format event isn't firing unless I switch from design to print preview. Very odd.
    OK - figured out that one too. The default view was Report View. Since it was only 1 page, I didn't notice.

  9. #9
    Gicu's Avatar
    Gicu is offline VIP
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Hi Angie,

    In these cases I try to let the data do the heavy work. Try to remove the labels and incorporate the label captions in the control source property of the related textboxes - the nice thing now is that you can set the font of the string portion whatever you like it (bold, bigger font, etc.) to emulate a label.
    So in your case the control source for the FinancedPrice" text box would be ="YourCaptionForLabel163" + [FinancedPrice]. The + operator will then do the work and make the control source null when any of the operands is null (in your case the FinancedPrice).

    Cheers,
    Vlad

  10. #10
    angie is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2013
    Posts
    232
    Quote Originally Posted by davegri View Post
    OK, this code will explicitly set the property:

    Code:
    Private sub Report_Load()
    If Nz(Me.FinancedPrice, 0) = 0 Then 
        Me.Label163.Visible = False
    else 
        Me.Label163.visible = true
    endif
    If Nz(Me.CashPrice, 0) = 0 Then 
        Me.Label164.Visible = False
    else
        Me.Label164.Visible = true
    end if
    If Nz(Me.EstPayments, 0) = 0 Then 
        Me.Label91.Visible = False
    else
        Me.Label91.Visible = true
    End if
    End Sub
    If this doesn't work, then try putting the code in the Report_Open event instead.
    good morning, could please explain the code above please. If I wanted to say if the field is null than hide label but if field is not null show label, could I just change the 0 to null and not null?
    thank you

  11. #11
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    The Nz function is designed to deal with exactly this situation.
    If there is a null value it is 'replaced' with 0 to allow the code to work

    If you try your own suggestion, you'll soon realise the answer
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  12. #12
    Gicu's Avatar
    Gicu is offline VIP
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Angie,

    The code you have would not work in the Report_Load event. It will need to be moved to the format or print event of the section containing the controls (the text boxes with the values and the associated labels). Have you tried my suggestion of eliminating the labels and incorporating their caption in the control source properties of the textboxes?

    Cheers,
    Vlad

  13. #13
    angie is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2013
    Posts
    232
    Its the same for me. in report view it did not show correctly, but if I switched to print view it was correct.
    I guess there is no way to fix this, but at least it works. Thank you I will keep on trying to find a way to do it... Thank you

  14. #14
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    The format event won't work in report view as noted on post 6. For that view try the other events, also mentioned there.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. hiding a button on a report line
    By StuartR in forum Reports
    Replies: 2
    Last Post: 02-23-2018, 01:30 PM
  2. need help on hiding empty space on report
    By nishant.dhruve in forum Access
    Replies: 2
    Last Post: 08-18-2016, 11:06 AM
  3. Hiding buttons on Print of Report
    By CS_10 in forum Reports
    Replies: 3
    Last Post: 04-08-2014, 07:52 AM
  4. Hiding an Empty Sub-report
    By ophirw in forum Reports
    Replies: 16
    Last Post: 10-04-2011, 09:37 AM
  5. Hiding checkbox on report
    By bluezidane in forum Reports
    Replies: 2
    Last Post: 06-29-2011, 12:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums