Using a class module as an instance for each image at run time, you have the absolute control of each image in one code module.
Create a class module (name it as clsMenuImage) and add this code:
Code:
Option Compare Database
Option Explicit
Private WithEvents mMenuImage As Image
'
Property Get MenuImage() As Image
Set MenuImage = mMenuImage
End Property
Property Set MenuImage(value As Image)
Set mMenuImage = value
End Property
Private Sub mMenuImage_Click()
With mMenuImage
MsgBox "Click " & .Name, , "Class clsMenuImage"
.Parent.MenuClick .Name 'Callback procedure of the form
End With
End Sub
To use this class in [any] form with images, you need code [at least] like this:
Code:
Option Compare Database
Option Explicit
Private mColMenu As Collection 'A collection for the clsMenuImage instances
Function MenuImages() As Collection
If mColMenu Is Nothing Then
Dim clsImg As clsMenuImage
Dim c As Control
'Keep an instance of clsMenuImage for each image
Set mColMenu = New Collection
For Each c In Me.Controls
If c.Name Like "imgMenu*" Then
c.OnClick = "[Event Procedure]" 'Enable the Click event
Set clsImg = New clsMenuImage 'Create a new instance
Set clsImg.MenuImage = c 'Set the MenuImage of this instance to this image
mColMenu.Add clsImg, c.Name 'Push it in collection
End If
Next c
End If
Set MenuImages = mColMenu
End Function
Private Sub Form_Load()
MenuImages 'Initialize MenuImages collection
End Sub
Private Sub Form_Close()
Set mColMenu = Nothing 'Release the collection with all instances
End Sub
Public Sub MenuClick(strImage As String)
'Callback procedure. Calling from clsMenuImage
MsgBox "Click " & strImage, , "Form Menu"
End Sub
(apply the LIKE pattern to your needs)
Take a look in attachment for a simple demonstration of the benefits of this option.