UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Userform Vba Code To Show Image, Office 2010    
 
   
dadof3
post Jul 23 2019, 03:33 PM
Post#1



Posts: 245
Joined: 31-December 02



I have a userform with a yes/no checkbox.

I would like an image to appear on the userform if the checkbox is checked

The value of the checkbox always outputs true or false onto the spreadsheet.

The image is saved on the desktop (for now, that will change once I figure out the vba code)

I'm new so I'm stumbling myself through this but I get the most of it, just can't find the code for this one?
Go to the top of the page
 
ADezii
post Jul 24 2019, 07:31 AM
Post#2



Posts: 2,625
Joined: 4-February 07
From: USA, Florida, Delray Beach


This is one of those cases where a 'Picture is worth a thousand words'. I uploaded a Demo for you consisting of two Files, a Macro Enabled Workbook (*.xlsm) and a Graphic File (Demo.bmp). Unzip both Files to the 'same' Folder, Open the Workbook, and select/deselect the Checkbox. If you have any further questions, we are here.
Attached File(s)
Attached File  Show_Image.zip ( 36.53K )Number of downloads: 5
 
Go to the top of the page
 
dadof3
post Jul 24 2019, 01:19 PM
Post#3



Posts: 245
Joined: 31-December 02



That is truly amazing sir! Thank you so much - works great! notworthy.gif

One more question if I may be so bold, this is the code I used based off of your download:

/CODE/
Private Sub chkHandicap_Click()
Dim strpath As String

strpath = ActiveWorkbook.Path
With Me
If ![chkHandicap] Then
![imgHandicap].Picture = LoadPicture(strpath & "\handicap.jpg")
Else
![imgHandicap].Picture = LoadPicture("")
End If
End With
End Sub
/END CODE/

I have another use for something exactly like this however, instead of a check box, I ALSO have a combobox users will choose from a selection of 7 options. Based on what they choose in the combobox, I would like a different image to appear for each 7 options in the combobox. How would I edit this code for something like that?
Go to the top of the page
 
ADezii
post Jul 24 2019, 02:11 PM
Post#4



Posts: 2,625
Joined: 4-February 07
From: USA, Florida, Delray Beach


This is one possible scenario, probably the simplest:
  1. Let's assume your Combo Box (ComboBox1) has the following seven options:
    • Image 1
    • Image 2
    • Image 3
    • Image 4
    • Image 5
    • Image 6
    • Image 7
  2. Let's also assume you have seven *.jpgs named: Image1.jpg, Image2.jpg...Image7.jpg in the same Folder as the Workbook. These Images coincide with the Combo Box Items, namely 1 thru 7.
  3. In the Change() Event of your Combo Box, place the following Code:
    CODE
    Private Sub ComboBox1_Change()
    Dim strPath As String

    strPath = ActiveWorkbook.Path

    With Me
      If IsNull(![ComboBox1]) Or ![ComboBox1] = "" Then
        ![Image1].Picture = LoadPicture("")
      Else
        ![Image1].Picture = LoadPicture(strPath & "\" & Replace(![ComboBox1], " ", "") & ".jpg")
      End If
    End With
    End Sub
  4. The Combo Items can match with the *.jpgs in any manner you wish, such as:
    CODE
    Picnic on Saturday ==> Picnic on Saturday.jpg
    Meeting at Moes ==> Meeting at Moes.jpg
  5. You can mismatch these elements, but then you would need a SELECT CASE...CASE..END SELECT Construct (NOT TESTED).
    CODE
    Private Sub ComboBox1_Change()
    Dim strPath As String

    strPath = ActiveWorkbook.Path

    With Me
      If IsNull(![ComboBox1]) Or ![ComboBox1] = "" Then
        ![Image1].Picture = LoadPicture("")
      Else
        Select Case ![ComboBox1]
          Case "Option 1"
            ![Image1].Picture = LoadPicture(strPath & "\" & "Graphic for Option 1.jpg")
          Case "Option 2"
            ![Image1].Picture = LoadPicture(strPath & "\" & "Graphic for Option 2.jpg")
          Case "Option 3"
            ![Image1].Picture = LoadPicture(strPath & "\" & "Graphic for Option 3.jpg")
          Case "Option 4"
            ![Image1].Picture = LoadPicture(strPath & "\" & "Graphic for Option 4.jpg")
          Case "Option 5"
            ![Image1].Picture = LoadPicture(strPath & "\" & "Graphic for Option 5.jpg")
          Case "Option 6"
            ![Image1].Picture = LoadPicture(strPath & "\" & "Graphic for Option 6.jpg")
          Case "Option 7"
            ![Image1].Picture = LoadPicture(strPath & "\" & "Graphic for Option 7.jpg")
          Case Else
            'Should never happen
        End Select
      End If
    End With
    End Sub

This post has been edited by ADezii: Jul 24 2019, 02:31 PM
Go to the top of the page
 
dadof3
post Jul 25 2019, 03:57 PM
Post#5



Posts: 245
Joined: 31-December 02



Works like butter! Thanks!!!
Go to the top of the page
 
ADezii
post Jul 26 2019, 06:45 AM
Post#6



Posts: 2,625
Joined: 4-February 07
From: USA, Florida, Delray Beach


yw.gif , Good Luck with your Project!
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    17th September 2019 - 04:19 AM