The message class - RAISING events

Thank you @cheekybuddha
I am getting
View attachment 120010
on the collection line for Unload, so I terminated Access. I could not get out of it otherwise.
Now on starting and opening the form, it is complaing the same for the collection Add?

Code so far

Code:
Option Compare Database
Option Explicit

Private Declare PtrSafe Function URLDownloadToFile Lib "urlmon" _
    Alias "URLDownloadToFileA" (ByVal pCaller As LongPtr, _
    ByVal szURL As String, ByVal szFileName As String, _
    ByVal dwReserved As LongPtr, ByVal lpfnCB As Long) As LongPtr
Private Const cstrAlphabet As String = "#ABCDEFGHIJKLMNOPQRSTUVWXYZ"
'Dim WithEvents mlClsAlphaCmd As ClsAlphaCmd
Private m_colAlphaCmds As Collection

Private Sub Form_Load()
Call SetAlphaButtons ' Initialise the command buttons via a class
End Sub
Private Sub SetAlphaButtons()
' Use clsAlphaCmd for the buttons for alphabet
Dim i As Integer
Dim acmd As New ClsAlphaCmd
For i = 1 To 2
    Debug.Print Me.Controls("AlphaTab" & i).Caption & " - " & Me.Controls("AlphaTab" & i).Name
'    Set Me.Controls("AlphaTab" & i) = mlClsAlphaCmd()
    Set acmd = New ClsAlphaCmd
    Call acmd.fInit(Me.Controls("AlphaTab" & i), i)
    m_colAlphaCmds.Add acmd, "AlphaTab" & i
Next
End Sub

Private Sub Form_Unload(Cancel As Integer)
Dim i As Integer, strAlpha As String

strAlpha = "AlphaTab" & i
For i = 1 To 27
    m_colAlphaCmds.Remove strAlpha
Next
End Sub
I have had to comment out the remove line to be able to get into design view.
ClsAlphaCmd doesn't raise events. That is why the compiler complained.

Dim mlClsAlphaCmd As ClsAlphaCmd will compile without that error.

The next thing is to use error handlers. I use MZ-Tools which allows me to actually set up my own error handler code which I can insert at the click of a menu item. You have probably seen them in my code already.

And finally, just set m_colAlphaCmds to nothing which destroys the collection itself and anything in it goes as well.
 
You can just paste those into the thread I started and delete these.
Yes, I will have to do that, as moving posts is not possible, just threads.
 
You can just paste those into the thread I started and delete these.
I can only do that for my posts. :(
Let's just leave them there and move to your thread.
 
Sorry John, I am going to give up proofing the book.
I can see that I should leave classes well alone :( , and concentrate on string theory. :)
 
Sorry John, I am going to give up proofing the book.
I can see that I should leave classes well alone :( , and concentrate on string theory. :)
Sigh. I appreciate all you have done.

I was getting ready to introduce clsActiveTrash! A pair of check boxes, bound to a pair of boolean fields, used to allow the dev to prevent deletions and yet allow the user to think they had deleted stuff.

This is a great class to earn pizza from the user.
"Sir, I am desperate. I just deleted a record i shouldn't have"
"Order a pizza and sit down, I'll fix it"

The dev asks a few questions, finds the record, which hasn't really been deleted. Brings it back to life.
The user leaves, so very grateful. Not realizing that the pizza will be delivered in a couple of moments...:):LOL::ROFLMAO:

Works every time!
 

Users who are viewing this thread

Back
Top Bottom