Help
I have a form where I am trying to load Icons to subsequently display in a
Tree menu system. The following 2 bits of code are run on the OnOpen Event
after clearing out the old images.
The form has a MSComctlLib.ImageListCtrl.2 control on it.
The IconTable contains the name of the icon e.g. Folder_Open.ico and a
number
The 11 images were originally loaded "by hand"
After running the initialize routine if I type ?
ImList.Object.ListImages.Count in the immediate window I get as expected 0,
but if I look at the ImList control, all 11 images are still there
Function ImageList_Initialize(ByVal ImageList As Object)
On Error GoTo ImageList_Initialize_Error
ImageList.ListImages.Clear
ImageList_Initialize_Error:
If Err Then MsgBox Err.Description, vbCritical, "No." & Err.Number
End Function
If I manually delete the images, the following routine does not add them
back
Function ImageList_Fill(ByVal ImageList As Object, ByVal IconTableName As
String) As Boolean
On Error GoTo ImageList_Fill_Error
'* ImageList-Variablen definieren
Dim img As ListImage
'* DAO-Variablen definieren
Dim MyDb As Database
Dim IconTable As Recordset
'* Funktion initialisieren
ImageList_Fill = False
ImList.Object.ImageWidth = 16
ImList.Object.ImageHeight = 16
'* DAO-Variablen initialisieren
Set MyDb = CurrentDb()
Set IconTable = MyDb.OpenRecordset(IconTableName, dbOpenDynaset)
'* Wenn kein Datensatz vorhanden, dann Abbruch!
If IconTable.RecordCount = 0 Then GoTo ImageList_Fill_Exit
IconTable.MoveFirst
While Not IconTable.EOF
'* kleine Images in ImageList einfügen
If Dir(CoIconPath & "\" & IconTable![IconName] & ".ico") "" Then
' Found
Set img = ImageList.ListImages.Add(IconTable![IconNo] + 1,
IconTable![IconName], _
LoadPicture(CoIconPath & "\" & IconTable![IconName] &
".ico"))
End If
IconTable.MoveNext
Debug.Print ImList.Object.ListImages.Count
Wend
'* Funktion erfolgreich!
ImageList_Fill = True
ImageList_Fill_Exit:
'* DAO-Variablen schliessen
IconTable.Clone
MyDb.Close
'* DAO-Variablen terminieren
Set IconTable = Nothing
Set MyDb = Nothing
ImageList_Fill_Error:
If Err Then MsgBox Err.Description, vbCritical, "No." & Err.Number
End Function
Can anyone point me in the right direction. It is a pain in the a.. loading
the images by hand
Many thanks
Phil
PS Sorry about the German. Can't remember where I nicked the original code
from