How to make image on report visible using yes/no field as criteria

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • KiwiGenie
    New Member
    • Mar 2007
    • 41

    #1

    How to make image on report visible using yes/no field as criteria

    I have an image on my report that I want to make visible only when a yes/no field is true. The yes/no field is a hidden text box called txtTried. The code I've been trying to use is:
    Code:
    If Me!txtTried = True Then
        Me.imgBerry.Visible = True
    Else: Me.imgBerry.Visible = False
    End If
    I got this to work on a form by using the same code in the Form_Current event, but it won't work in my report. Have tried it in the Report_Current, Report_Activate , Report_Load, Report_Open, and Detail_Format events, nothing happens in any of those except the Report_Open one gives an error saying can't find the field, control, or property, and in debug mode the first line of code is highlighted.
    Not sure if I'm making sense, can anyone help me with this?
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    1. The [Tried] Field in the underlying Data Source should be a Yes/No Field represented by a Check Box, and not a Text Box.
    2. Change the Control Name to chkTried in the Detail Section of your Report.
    3. Place the following, single line of Code, in the Format() Event of the report's detail Section.
      Code:
      Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
        Me![imgBerry].Visible = Me![chkTried]
      End Sub

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32669

      #3
      From your question it's not clear if the Yes/No control you refer to (as a field) is on the form still, or has been duplicated to the report to match a field in the record source. If the former, then you will have problems referencing the control. We could help with that if more info were available. If the latter then ADezii's post should solve your problem. The control should certainly be a CheckBox and not a TextBox, and the code he provided is preferable to yours, which should work fundamentally, but is overly complicated for the task. If so, you may choose to mark his post as the best answer.

      Comment

      • KiwiGenie
        New Member
        • Mar 2007
        • 41

        #4
        Yes I did have the yes/no field on the report as well, so changing it to a checkbox and changing the code did get it all working. If only experience with code-writing was something that could be gotten quicker!
        Thank you both so much for your help :)

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32669

          #5
          It's a pleasure, and especially so when members display such good manners :-)

          Comment

          Working...