Microsoft
Software
Hardware
Network
Question : Image1.Picture = LoadPicture(...) fails in VBA -- Workarounds please?
I need a way to display the images that are stored in an ImageList on my form. The ImageList absolutely must be populated at run-time.
One of the ways I have tried to do this is to create an Image and ImageList control on the form and then in the event handler for a command button I populated the ImageList. For example:
With ImageList1
.ImageWidth = 16
.ImageHeight = 16
.ListImages.Add Picture:=LoadPicture(Curre
ntProject.
Path & "\icons\drive16.ico") ' index 0
.ListImages.Add Picture:=LoadPicture(Curre
ntProject.
Path & "\icons\fldclosed16.ico") ' index 1
.ListImages.Add Picture:=LoadPicture(Curre
ntProject.
Path & "\icons\fldopen16.ico") ' index 2
.ListImages.Add Picture:=LoadPicture(Curre
ntProject.
Path & "\icons\share16.ico") ' index 3
.ListImages.Add Picture:=LoadPicture(Curre
ntProject.
Path & "\icons\shortcut16.ico") ' index 4
End With
Image1.Picture = ImageList1.Overlay(2, 1)
But this gives an error like the following:
Run-time error '2220'. Microsoft Access can't open the file '27789625'
I get the same error when I do a command like this:
Image1.Picture = LoadPicture(CurrentProject
.Path & "\icons\drive16.ico")
So if you can solve either of those problems, you've probably solved both of them.
The problem is apparently that, although this will probably work in normal VB (or at least if one uses a PictureBox instead of an image), "VBA will not allow assignment of bitmap handles at runtime using LoadPicture() to ANY object that has a .Picture property."
This was noted in a previous EE posting at
http://www.experts-exchang
e.com/Appl
ications/Q
_20971886.
html
. However, the poster's plea for a workaround seems to unanswered. "If anyone knows of a work around ... to accomplish this, please let me know."
Does anyone know of a workaround?
It seems pretty clear that the Image control just plain won't let me do what I want to do. So a possible solution would be to find another simple (and free) control (an *ActiveX* control, probably, not a built-in VBA control) that has a Picture property that accepts the handle of a picture (a Picture object). Searching the Web, I have not found anything that meets these criteria. Sure, there are PictureBox ActiveX controls, but they cost money and besides that are probably more powerful than I need. I just need a plain PictureBox (or similar) ActiveX control with a Picture property.
Or is there a way to do this using what is built-in to VBA/Access?
Thanks in advance,
Tyler
Answer : Image1.Picture = LoadPicture(...) fails in VBA -- Workarounds please?
Closed, 250 points refunded.
modulo
Community Support Moderator
Experts Exchange
Random Solutions
Excel closes unexpectedly, without saving work when opening outlook e-mail
How to revert back the saved file in MS word?
SQL Server problem with date format
Overlap CTreeCtrl and multiline CEdit in dialog
Microsoft, Server 2003, SP2 Bugcheck 0x0000000a Problem
Difference between XmlDocument and XmlDataDocument in .NET
Am trying to get a MAS90 VI Job to run from WinExec(). Runs fine from command prompt, but not from WinExec().
Reusing an iif statement in MS Access
Unlocking file in WPF
Impoting xls sheet into Microsoft acces existing table