Great Function - if it worked....!

epicmove

Ben
Local time
Today, 13:21
Joined
Apr 21, 2006
Messages
59
Hi guys,

I have written a function to link CmdButton images on my forms.
This enables the .mde to be installed anywhere and as long as the images folder in installed into the same directory, the images will show.

The function (not exact as its on my other PC is as below):
Code:
Public Function GetCmdButtonImages()
Dim ctl as Control
Dim ImagePath as String

Set MyForm = Forms(Current)
For Each ctl in MyForm.Controls
Select Case ctl.ControlType
Case acCmdButton
ImagePath = Application.CurrentProject.Path & "\images\" & ctl.name & ".bmp"
ctl.Picture = ImagePath
End Select
Next ctl

End Function

Syntax may not be exactly correct as its from memory but it basically cycles through each command button and loads the relevant image.
My problem is that this will only run on one form at a time i.e. Forms(current).
As my main menu is open all the time it means when i call this function in the open of event of any other forms, it does not work.

What do I need to set "MyForm" to, to allow the function to work on any form that opens.
Also how can I get this to work on subforms? Do I need to cycle through each form first?

Thanks
Ben
 
Once I embed an image into a button, I can trash the source pic and it still works. (Access 2003)
 
yes I am aware this works. Not what I am after though.
I do not want to embed the image as this will contribute to the file size of the front end.
The idea is that the image folder can be dropped into the same directory as the FE. However the above function can only be run on one form at a time. Hence my problem.....
 
Code:
Public Function GetCmdButtonImages(frm as form)
Dim ctl as Control
Dim ImagePath as String

Set MyForm = frm
For Each ctl in MyForm.Controls
Select Case ctl.ControlType
Case acCmdButton
ImagePath = Application.CurrentProject.Path & "\images\" & ctl.name & ".bmp"
ctl.Picture = ImagePath
End Select
Next ctl

End Function

On each form load use:

Code:
GetCmdButtonImages Me

This should give you what you want.

scotty
 
How about setting the picture type of the button/control to linked rather than embed?
 
thanks scotty

will give this a try tomorrow.

thought it would be something like this where I have to pass the frm to the function.......learning all the time :)

Thanks again

Ben
 

Users who are viewing this thread

Back
Top Bottom