Results 1 to 10 of 10
  1. #1
    Jessica240 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    95

    Changing visibility of image based on value in text box

    Hello,

    I have a subreport that works perfectly when I open it by itself. When I open the main report that contains the subreport, the image that should be visible is not, and the image that should not be visible is.

    Here is my code in the subreport:

    If Me.Text49.Value = Me.Txt1 Then
    Me.Image1.Visible = True
    Else: Me.Image1.Visible = False
    End If
    If Me.Text49.Value = Me.Txt2 Then
    Me.Image2.Visible = True
    Else: Me.Image2.Visible = False
    End If



    The main report does not include any code. I'm not sure how to reference the objects in the subreport in the coding of the main report. Is that what I need to do? If so, how do I reference the images and text boxes contained in the subreport within the code of the main report? (text49, txt1, and txt2 are text boxes; image1 and image2 are images)

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    That code should work the same regardless if the report is independent or subreport. It does for me.

    What event is the code in? What section are the images in?

    Could simplify to 2 lines:

    Me.Image1.Visible = Me.Text49.Value = Me.Txt1
    Me.Image2.Visible = Me.Text49.Value = Me.Txt2
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Jessica240 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    95
    The code is on the "On Load" Event. Should it be on a different event? Perhaps the "On Open" event?

    The images and text boxes are located in the report footer.

    Thanks for the help by the way. I certainly appreciate it!

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    try the onformat event for the section the image controls are in

  5. #5
    Jessica240 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    95
    I tried your idea, Ajax, but unfortunately that didn't work. Any other ideas? Anyone?

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    It works if the report is opened in PrintPreview or direct to printer, not ReportView.

    What do you mean by "didn't work" - error message, wrong results, nothing happens?

    There is a way to do this without VBA and it will work in either ReportView or PrintPreview. Involves an IIf() conditional expression in image ControlSource property pulling images from external file location.

    If you want to provide db for analysis, follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    Jessica240 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    95
    I will provide the db for analysis, but I need a little time to remove the confidential elements from the data first.

    Using Ajax's idea: I opened the sub report on its own in report view and got the same results as when I opened the main report: the image that was supposed to be visible was invisible and the image that was supposed to be invisible was visible. When I put the code back in the onload event and open the subreport on its own in report view it works perfectly. So strange.

  8. #8
    Jessica240 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    95

    Post

    The db file for analysis is attached. Please let me know if you have any questions.

    Thanks,

    Jess
    Attached Files Attached Files

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    OnLoad event of a form used as subform does not trigger.

    OnFormat event only triggers in PrintPreview or direct to printer.

    Set the DefaultView property to PrintPreview for BOTH reports.

    Simplified code.
    Code:
    Private Sub ReportFooter_Format(Cancel As Integer, FormatCount As Integer)
    Me.Image1.Visible = Me.Text49.Value = Me.Txt1
    Me.Image2.Visible = Me.Text49.Value = Me.Txt2
    Me.Image3.Visible = Me.Text49.Value = Me.Txt3
    Me.Image4.Visible = Me.Text49.Value = Me.Txt4
    Me.Image5.Visible = Me.Text49.Value = Me.Txt5
    Me.Image6.Visible = Me.Text49.Value = Me.Txt6
    Me.Image7.Visible = Me.Text49.Value = Me.Txt7
    Me.Image8.Visible = Me.Text49.Value = Me.Txt8
    Me.Image9.Visible = Me.Text49.Value = Me.Txt9
    Me.Image10.Visible = Me.Text49.Value = Me.Txt10
    Me.Image11.Visible = Me.Text49.Value = Me.Txt11
    Me.Image12.Visible = Me.Text49.Value = Me.Txt12
    Me.Image13.Visible = Me.Text49.Value = Me.Txt13
    Me.Image14.Visible = Me.Text49.Value = Me.Txt14
    End Sub
    If you must use ReportView, review post 6.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    Jessica240 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    95
    Wow June. You really saved me. Thank you so much! That worked. You are absolutely amazing!!!!!

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

Similar Threads

  1. Replies: 5
    Last Post: 04-14-2016, 04:01 PM
  2. Replies: 16
    Last Post: 03-03-2014, 10:46 AM
  3. Replies: 2
    Last Post: 01-31-2013, 07:44 PM
  4. Replies: 8
    Last Post: 01-25-2012, 02:07 PM
  5. Visibility based on Combo selection
    By jlclark4 in forum Forms
    Replies: 1
    Last Post: 12-22-2010, 11:42 AM

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