LoadPicture Command throwing error

RawlinsCross

Active Member
Joined
Sep 9, 2016
Messages
437
Good day,

I have a userform with 31 image controls (on for each day of the month of May) which populate with pictures from a folder that are all contain dates (again in May) in the name. I then extract the date from the filename and find the correct image control to place it in. The code works until I try to upload the picture into the image control - throws the error "Compile Error: Wrong number of arguments or invalid property assignment" - not sure what the problem is.


Code:
Private Sub LoadPicture()

Dim FileSys As FileSystemObject
Dim myFolder
Dim strFilename As String
Dim objFile As File
Dim PicDay As Long

'set path for files
Const myDir As String = "[URL="file://\\netapp6\tempstor\John"]\\netapp6\tempstor\John[/URL] Halfyard\Nickel Pictures\GIMP"

'set up filesys objects
Set FileSys = New FileSystemObject
Set myFolder = FileSys.GetFolder(myDir)

'go through tempstor and cycle through pictures
For Each objFile In myFolder.Files
    PicDay = Mid(objFile.Name, 15, 2)  'this returns the day of the month
    'each image control is labelled "Month1, Month2, Month3, etc)
    Me.Controls("Month" & PicDay).Picture = LoadPicture(myDir & Application.PathSeparator & objFile.Name)
Next objFile

Set FileSys = Nothing
Set myFolder = Nothing

End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Does it fail for all files or just a particular one? What format are they, and can you manually load them into the control(s)?
 
Upvote 0
The files are in *.jpeg files and yes, I can go into the properties of say "Month1" and under the Picture property load up any of the files. It appears none of the files are getting loaded.
(note, when I manually enter the picture the picture reads "(Bitmap)")
 
Last edited:
Upvote 0
Have you verified that objFile.Name is returning the correct value?
 
Upvote 0
Yes, the entire name (with the correction filename extension) reports out when I go a MsgBox. But I had to comment out the "LoadPicture" line to get this even to run. It's not a runtime error and throws an error on compiling.
 
Upvote 0
Just re-read your code - change the name of your routine to something other than LoadPicture! ;)
 
Upvote 0
okay, I would NOT have gotten that in a million years! And of course, it works like a charm when I renamed it "LoadImage". Nice lesson on 'key words'. Thanks!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,510
Messages
6,114,048
Members
448,543
Latest member
MartinLarkin

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