PDA

View Full Version : Solved: Updating image on form



nst1107
11-22-2008, 12:21 AM
I have an image (Image1) on a form. On Image1_DoubleClick, I have the user select a file to upload to the image control. The problem is I don't know how to then set the selected file as the picture for the image. Here's what I have:

Private Sub Image1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim pic As Object
ChDrive (ThisWorkbook.Path)
ChDir (ThisWorkbook.Path)
r = Application.GetOpenFilename("Picture Files (*.bmp; *.cur; *.gif; *.ico;_
*.jpg; *.wmf),*.bmp; *.cur; *.gif; *.ico; *.jpg; *.wmf", , "Load Image")
If r = False Then Exit Sub
'Image1.Picture = r
'set pic = createobject("Excel.
End Sub

Setting the Picture property of Image1 to the selected filename (r) didn't work because r is a string. Setting pic = CreateObject(...) didn't work, because I barely know how to use that function. Just remember seeing it somewhere in this forum.... Any suggestions?

GTO
11-22-2008, 01:00 AM
Greetings Nate, and nice to "meet".

This should work. LoadPicture is not well described in help (leastwise as far as info I could find), but is the way to assign the picture.

@Anyone:
As to the help topic for 'Picture Property', it only shows the pathname arg. Yet when entering in 2003, additional args: "widthDesired:= ,heightDesired:= ,flags:= " (As LoadPictureConstants) appear. Anyone know how these work?

Hope this helps,

Mark


Private Sub Image1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim pic As Object
ChDrive (ThisWorkbook.Path)
ChDir (ThisWorkbook.Path)

'//added as I use Option Explicit//
Dim r
'// Maybe you inserted the continuation just for the post, else, I thought //
'// to mention that this errors. It is missing what I indicate in purple //
' r = Application.GetOpenFilename("Picture Files (*.bmp; *.cur; *.gif; *.ico; _
*.jpg; *.wmf),*.bmp; *.cur; *.gif; *.ico; *.jpg; *.wmf", , "Load Image")

r = Application.GetOpenFilename("Picture Files (*.bmp; *.cur; *.gif; *.ico;" & _
" *.jpg; *.wmf), *.bmp; *.cur; *.gif; *.ico; *.jpg; *.wmf", , "Load Image")

If r = False Then Exit Sub

'Image1.Picture = r
'set pic = createobject("Excel.
Image1.Picture = LoadPicture(Filename:=r)
Me.Repaint
End Sub

nst1107
11-22-2008, 09:16 AM
Thanks, Mark. It works like a charm. And, yes, it was 1 in the morning and I just tossed in the continuations without paying attention. Sorry about that.

GTO
11-22-2008, 02:25 PM
Thanks, Mark. It works like a charm. And, yes, it was 1 in the morning and I just tossed in the continuations without paying attention. Sorry about that.

Hey Nate,


Thanks for getting me chuckling :-) Its nice to know I'm not the only one who sometimes attends class in "delirium coding 101", as I certainly have oft done so... (I really like the next day when I get to look and wonder what it was supposed to be!)

Now I'm still just hoping someone will explain those "extra" args...

Have a great weekend,:thumb

Mark