Image load

ebea

Active Member
Joined
Jul 12, 2008
Messages
296
Office Version
  1. 2021
Platform
  1. Windows
Hi! A problem, loading pictures into an image form. I use the image on a UserForm, together with Textboxes, which are loaded by the following code:

But I can't get the images to load as wanted. I have set image name for all rows, into Column O (in this case).
I get the error message "Path not found". And no matter how I set the path, it comes with an error. If I load image "normally", as this: Image1.Picture = LoadPicture("C:\xxx\xxx\1001.jpg") it will works.
Does anybody have a guess of the problem?
Code:
Private Sub CommandButton1_Click()
   Box = TextBox14.Value
    With Sheets("dj")
        For Rows = 3 To .UsedRange.Rows.Count
            If Int(Range("B" & Rows).Value) = Int(Box) Or Range("B" & Rows).Value = Box Then
                TextBox1.Value = .Range("B" & Rows).Value
                TextBox2.Value = .Range("C" & Rows).Value
                TextBox8.Value = .Range("D" & Rows).Value


                Image1.Picture = LoadPicture("C:\xxx\xxx").Range("O" & Rows).Value

Exit Sub
            End If
        Next Rows
    End With
End Sub
 
Last edited by a moderator:

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Yes, I know this. But it has not being the problem, as it is correct in the "original" string. I will work further, to see if I can find the problem, while the Grey Hair grows! I have another problem too, which are related to shifting page in the Multipage selection, which gives an Error 13.

So far, thanks for you'r help, and time!
 
Upvote 0
Well I think it is the problem.

Here is a working version of the code. Change folder location as required.

Code:
Private Sub CommandButton1_Click()
    Dim rws As Long, Box As String, LstRw As Long, sh As Worksheet

    Set sh = Sheets("dj")
    Box = TextBox14.Value

    With sh
        LstRw = .Cells(.Rows.Count, "B").End(xlUp).Row
        For rws = 3 To LstRw
            If Range("B" & rws).Value = Box Then

                TextBox1.Value = .Range("B" & rws).Value
                TextBox2.Value = .Range("C" & rws).Value
                TextBox8.Value = .Range("D" & rws).Value


                Image1.Picture = LoadPicture(("S:\Stairs\Stair Pics\") & Range("O" & rws).Value)

                Exit Sub
            End If

        Next rws

    End With

End Sub
 
Upvote 0
Thank you, Dave. I will test it out, later in the Evening.
 
Upvote 0
...So! Now I finally found the reason for why I get Grey Hair, because of this error, and why it did not work. I tried you'r code, and it did not work!! And then I knew, that the problem had to be related to other things, as the code itself.
A little background explanation! I have a userForm, where I have a Multipage configuration, with 3 pages. And when I start this, I have all the time stands on a sheet, with a name, other than this who was the first page (tab) startup in the Multipage setup . So when I did made the sheet "dj" the active sheet, and did start the userform with the Multipage, it suddenly all works, and also your code.
But when I make one of the other sheets active, and start up the Userform, it fails again (as all the time), and also your code. So what it is in the Mutipage setup is doing, I have to find out, because as now, I can't use it, as it was my intension.
So I'm a bit lost, of why it is so in a Mutipage configuration, that the sheet who are related to the actual tab, has to be active! If I shift tabs on the Multipage, and stands on a sheet not related to the tab choice, i get an error, as I have done, all the time, even that I have the code calling the right sheet :(

So if you have any good ideas, you are greatly welcome!

But so far, thanks for you'r help.
 
Upvote 0
Yes, I know this. But try read what I wrote! It should not matter, in which sheet you stands on, when you start the Userform. It stands in code to look at sheet "dj". But if I start up, standing on another sheet, it don't work! And it must be related to some with the Multipage setup, or the Multipage Control itself!
 
Upvote 0
I think I have located the issue, Range("O" & rws).Value) was not qualified. Needs a period in front of it or it will think it's for the active sheet



Code:
Private Sub CommandButton1_Click()
    Dim rws As Long, Box As String, LstRw As Long, sh As Worksheet

    Set sh = Sheets("dj")
    Box = TextBox14.Value

    With sh
        LstRw = .Cells(.Rows.Count, "B").End(xlUp).Row
        For rws = 3 To LstRw
            If Range("B" & rws).Value = Box Then

                TextBox1.Value = .Range("B" & rws).Value
                TextBox2.Value = .Range("C" & rws).Value
                TextBox8.Value = .Range("D" & rws).Value


                Image1.Picture = LoadPicture(("S:\Stairs\Stair Pics\") & .Range("O" & rws).Value)

                Exit Sub
            End If

        Next rws

    End With

End Sub
 
Last edited:
Upvote 0
The same goes for this as well needs to be qualified.
Code:
 If .Range("B" & rws).Value = Box Then
 
Upvote 0
You was right Dave! that was the reason. Now it starts without problem, no matter which sheet I "stands" on.
But it still give problems, when I shift from tab to tab, in the Multipage control. I can shift now, but I can't list up pictures and text, more than once, before it stops with nearly same error, telling picture path is not correct.
So it's upwards!
But so far, a great thanks for your time and help. If you come up with the "golden" moment, let me hear ;)
 
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,187
Members
449,071
Latest member
cdnMech

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