Question : Dynamically add images to an Access form with VBA

I want to use VBA to dynamically add and display images on a form. I want to read the file system for the image file paths then add images with these paths.

Reading the filesystem and fetching the image paths is no problem but I can't figure out how to dynamically add the Image controls.

I thought I would simply be able to create a new Image object then specify it's Parent, Picture, Visible, Top and Left properties. Something like this:

Set imageObj = New Image
imageObj.Parent =
imageObj.Picture = LoadPicture()
imageObj.Top =
imageObj.Left =
imagecombo_carImages.Visible = True

But this gives me the error "Active X component can't create object". Strange given that the Image control is a native Access control.

I need this to work in both Access 2000 and XP.

Any ideas? Thanks in advance...

Answer : Dynamically add images to an Access form with VBA

>>Adding controls at run time in Access is only going to cause you pain
I agree.
In fact, you can't add controls into a running form. You need to open the form in design view, add the control, save the form, close and reopen as running.

A real pain, for no real benefit.

Personally, I'd store the files externally and simply pass in their value from a table.
If there is no file/no value, show a default picture:

myPic = NZ(DLookup("picaddress", "table", "Recid =" & Me.Formcontrol),"defaultPicAddress")
Me.Imagecontrol.picture = myPic

Idea...?
Random Solutions  
 
programming4us programming4us