• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Showing multiple photos on the userform....

Status
Not open for further replies.

PP3321

Active Member
1. I have multiple photos in my folder on my pc(desktop)
2. I want to create slideshow for these photos on the userform.

3. I wrote below code, but it returns error.
It says file not found.

*I am basically trying to store all the photo names into array, and link the array to the image1 on the userform...


Could anyone please tell me what I am doing wrong here...?


Code:
Dim i As Long
Dim PhotoNames As String
Dim ArrayPhoto() As String

Private Sub UserForm_Initialize()

PhotoNames = Dir("C:\Users\Test\Desktop\FolderName\*.*")
ReDim ArrayPhoto(0)

Do While PhotoNames <> ""

i = UBound(ArrayPhoto) + 1

ReDim Preserve ArrayPhoto(i)

ArrayPhoto(i) = PhotoNames

Me.Image1.Picture = LoadPicture(ArrayPhoto(i))

PhotoNames = Dir()

Loop


End Sub
 
Something like below to load first image upon UserForm_Initialize.

However, you'd never want to loop through loading images in UserForm_Initialize. As UserForm won't be displayed until the code stops (i.e. you will only see last image).

Code:
Private Sub UserForm_Initialize()
Dim PhotoNames As String, fPath As String, iFile As String
Dim i As Integer
Dim ArrayPhoto() As Variant
fPath = "C:\Test\"
iFile = "*.*"
PhotoNames = Dir(fPath & iFile)
i = 0
Do Until PhotoNames = ""
    i = i + 1
    ReDim Preserve ArrayPhoto(1 To i)
    ArrayPhoto(i) = PhotoNames
    PhotoNames = Dir
Loop
Me.Image1.Picture = LoadPicture(fPath & ArrayPhoto(1))
End Sub
 
See attached with control assigned to Command buttons on userform.

Module1 contains Functions (PhotoNum & MaxPhoto) and Public Constant (fPath). Edit fPath string to suite your need.
 

Attachments

  • UserFormImage_Demo.xlsm
    21.6 KB · Views: 72
Oh my gosh.
I did not expect to receive the end-product!
Thank you so much!!!
You are truly awesome....!!!
 
Excellent Mr. Chihiro
It is really awesome

May you edit the code ..as the pictures loaded are not fit to the image tool..?
I mean to fix the dimension to suit the image tool
 
Hi Chihiro
I have more than 100 pictures in my folder.
I need to think about how to capture numbers more than 1 digit.
If you have any suggestion, could you please let me know...?

currPic = Left(Me.Label1.Caption, 1)
 
Excellent Mr. Chihiro
It is really awesome

May you edit the code ..as the pictures loaded are not fit to the image tool..?
I mean to fix the dimension to suit the image tool

YasserKhalil

I kind of fixed this problem by changing the image1 of the userform property.
Autosize = TRUE
 
Thanks for reply
I already tried this property before your reply but the same problem with me ..
But this line solved the problem
In userform initialize
Code:
Me.Image1.PictureSizeMode = fmPictureSizeModeZoom
 
Here. Changed few things around. Instead of having all "x/xx" in one label. Split them up in to different parts.

You can now also type in number in textbox and jump to that image.
 

Attachments

  • UserFormImage_Demo_v2.xlsm
    22.4 KB · Views: 84
is it possible month wise employess photos ,name , token no in one userform
when i select next month that month same showing details employee in one userform with his details
 
Here. Changed few things around. Instead of having all "x/xx" in one label. Split them up in to different parts.

You can now also type in number in textbox and jump to that image.
Hi All,
I'm getting a "Runtime error 9: Subscript out of range" error at the time it tries to Launch userform. Any ideas on how to resolve that? Checked a few tutorials and it seems it has something to do with the ArrayPhoto().

Thanks in advance
 
Hi All,
I'm getting a "Runtime error 9: Subscript out of range" error at the time it tries to Launch userform. Any ideas on how to resolve that? Checked a few tutorials and it seems it has something to do with the ArrayPhoto().

Thanks in advance
I believe in order for this to work, you will need to create the target folder that contain the images. I believe in this example its stored within
"C:\Test\"
Hope this help!
 
I believe in order for this to work, you will need to create the target folder that contain the images. I believe in this example its stored within
"C:\Test\"
Hope this help!
Thank you Mighty. Somehow, I was able to fix this, just by creating the folder. Now, the question is, whether I can save multiple photos using an attachment command button on the same user form and naming them based on a document number with which such attachments need to be. And later on, recall them by simply putting the document number again in a search box on the user form?
78650
 
Status
Not open for further replies.
Back
Top