Results 1 to 6 of 6
  1. #1
    Casey Sanders is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    37

    Question display image if checkbox is checked


    I have a checkbox field set up for products that have a particular feature. For instance, if the product has a lifetime warranty, the checkbox is checked. On my report, I have the checkboxes displaying and they either show the check or not, but the text and everything is still there on the ones that are not checked. I know I can hide it unless there is a value and only show it if it is checked, but how would I go about displaying a logo if the box is checked? Essentially, what I want to do is have a "Lifetime Warranty" logo display on the products that have a lifetime warranty, and the ones that do not, just show nothing...

    to be more specific, there are 2 options (checkboxes), of which only 1 will be checked (if any). If a product has Warranty A, I want to display image A....if the product has Warrany B, I want to display image B...if the product has our standard warranty, then I want to display no image. So I have 2 ideas on how to accomplish this: First, I can add an image for each of the warranties to the report where I would want it to show and set the visibility to no, then somehow code it so that if checkbox A is checked, then set image A visibility to yes and if checkbox B is checked, set image B visibility to yes. The other idea I have is to have an image box with visibility set to no, then have some code that says if checkbox A is checked, set control source to "path/imageA.jpg" or if checkbox B is checked, set control source to "path/imageB.jpg" (Possibly with an IF THEN statement?) ...I'm not very good with code yet, so if anyone could offer some help with this or show me a better way, it would be greatly appreciated. Thanks!

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,893
    Using code to set visibility property probably won't work if the report has multiple records displayed continuously in Detail section. The code would execute when the report first renders, read data from first record, set property and that setting will apply to all subsequent records.

    Recommend only ONE field for the warranty. If a Yes/No field then Yes means A and No means B. If a text field then options 'A' or 'B'.

    Try using the ControlSource property of Image control:

    =IIf([yes/no field name],"path\image",Null)
    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
    Casey Sanders is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    37
    OK, I tried code like that but when I hit report view it prompts me for the value of the path? It is a checkbox, but I need it to work for 2 different checkboxes, so the Yes/No field wouldn't work, per se. I'll try to elaborate a little more. There are essentially 3 options for warranty. Standard, EWP and SGR. 90% are standard and would not require any image or anything. EWP and SGR are 2 different types of warranty. Every record in the table has 2 checkboxes (one for SGR and one for EWP, but they are either/or and can not be both). So basically in the report I want no image to show UNLESS one of these two checkboxes are checked. If EWP is checked, then I want the EWP logo to display, and if SGR is checked, I want the SGR logo to display. And it is for multiple records. There are thousands of records and only a handful that are either SGR or EWP.

    The checkbox names are "SGR-Maxbond" and "EWP". So if I created an image control named "Warranty" and the path to the image is "C:\Users\graphics1.EZONAUTO\Desktop\images\" and the 2 image names are "SGR.jpg" and EWP.jpg", how would I code the control source?

  4. #4
    Casey Sanders is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    37
    Here is a link I found where someone accomplished something very similar...and they touched briefly on what you suggested, but this guy wasn't using a path and his image was embedded, so it didn't really go anywhere...either way, they got it figured out the way he was doing it, so I'm hoping to get this accomplished...seems fairly easy to do, I hate being new to this LOL

    EDIT: forgot the link!! http://www.access-programmers.co.uk/...=221802&page=2

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,893
    You don't need and should not have two check fields. Since a record can be only warranty A OR warranty B then this is a single field data.

    But if you insist, try:

    ="C:\Users\graphics1.EZONAUTO\Desktop\images\" & IIf([EWP], "EWP.jpg", "SGR.jpg")
    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.

  6. #6
    Casey Sanders is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    37
    I got it to work. I created 2 embedded image controls... one named EWP_logo and the other named SGR_logo (these are very small images...like 30kb, I figure embedding shouldn't hurt). I set both controls to visible and then put this code into the detail section of the report:

    Code:
    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    
    
    If Me.SGR_Maxbond = -1 Then
    SGR_logo.Visible = True
    Else
    SGR_logo.Visible = False
    End If
    
    
    If Me.EWP = -1 Then
    EWP_logo.Visible = True
    Else
    EWP_logo.Visible = False
    End If
    
    
    End Sub
    ...works like a charm

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

Similar Threads

  1. If checkbox is checked allow query to run
    By burrina in forum Forms
    Replies: 14
    Last Post: 01-29-2013, 03:56 PM
  2. VBA for testing if checkbox is checked
    By rhewitt in forum Programming
    Replies: 0
    Last Post: 09-26-2012, 07:11 AM
  3. Display Text Only if Checkbox is Checked
    By Rick5150 in forum Forms
    Replies: 2
    Last Post: 09-16-2012, 09:19 AM
  4. If checkbox is checked, add X to a current value
    By INeedAboutTreeFiddy in forum Programming
    Replies: 4
    Last Post: 05-30-2012, 08:17 AM
  5. Replies: 22
    Last Post: 11-14-2011, 10:29 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