Excel VBA Picture in UserForm by Value in TextBox

MichelVBA

New Member
Joined
Mar 28, 2025
Messages
10
Office Version
  1. 365
Platform
  1. Windows
Hi there, im looking for a code that shows a picture on my userform relatve to the value off the textbox thats also in the same userform.
Here below a screenshot of what i mean.
1743620405746.png
 
What does the textbox contain? If the textbox contains an image path, e.g. TextBox1.Value = "d:\hichic.jpg" then
Code:
Image1.PictureSizeMode = fmPictureSizeModeZoom
Image1.Picture = LoadPicture(TextBox1.Value) ' only BMP, GIF, JPG, WMF, EMF, ICO, CUR, Not PNG
 
Upvote 0
Dear @hungtbatman1 , i want the value in the textbox come from a datalist. See my other post (this one)for example
Therefor i used this code but its not correct.

Me.txtPict.Value = Me.lstPlanningslijst.List(Me.lstPlanningslijst.ListIndex, 33) 'in this row its says C:\Users\Images\Pict1.jpg
Me.Image1.PictureSizeMode = fmPictureSizeModeZoom
Me.Image1.Picture = LoadPicture(txtPict.Value)
 
Upvote 0
Dear @hungtbatman1 , i want the value in the textbox come from a datalist. See my other post (this one)for example
Therefor i used this code but its not correct.

Me.txtPict.Value = Me.lstPlanningslijst.List(Me.lstPlanningslijst.ListIndex, 33) 'in this row its says C:\Users\Images\Pict1.jpg
Me.Image1.PictureSizeMode = fmPictureSizeModeZoom
Me.Image1.Picture = LoadPicture(txtPict.Value)
1. Does the file "Pict1.jpg" exist in the folder "C:\Users\Images"? Have you checked?
2. You see "C:\Users\Images\Pict1.jpg" but I don't know if the text contains any invisible characters, e.g. spaces at the end.
3. Let's check. Add the following code to the above code:
VBA Code:
dim i as long, text as string
text = txtPict.value
Debug.Print Dir(text)
for i = 1 to len(text)
Debug.Print AscW(mid(text, i, 1))
next
Run the entire code -> copy the contents of the "Immediate" window -> paste it into the post so I can see what's there.
 
Upvote 0
Also the file path has to be a string. Maybe...
VBA Code:
Me.Image1.Picture = LoadPicture(CSTR(Me.txtPict.Value))
HTH. Dave
 
Upvote 0
Dear @hungtbatman1 and @NdNoviceHlp , after a couple of times to trying solving this problem it was the settings of the cell.
Now i have the next question....
I have the possibility to reset the form, only the picture remain to stay.
Maybe something like:
If there is no value in the textbox then load a picture (blanc)
 
Upvote 0
Dear @hungtbatman1 and @NdNoviceHlp , after a couple of times to trying solving this problem it was the settings of the cell.
Now i have the next question....
I have the possibility to reset the form, only the picture remain to stay.
Maybe something like:
If there is no value in the textbox then load a picture (blanc)
VBA Code:
Private Sub CommandButton1_Click()
    If txtPict.Value <> "" Then
        Image1.Picture = LoadPicture(txtPict.Value)
    Else
        Image1.Picture = Nothing         '   Image1.Picture = LoadPicture("C:\Users\Images\blanc.jpg")
    End If
End Sub
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top