Event Driven Programming with John Colby

GPGeorge

George Hepworth
Local time
Yesterday, 18:48
Joined
Nov 25, 2004
Messages
2,462
Event Driven Programming using classes can expand the power of Access applications.

Long-time Access developer and author John Colby will demonstrate and explain using classes in your own applications.

Events are the very essence of MS Windows and every application running on it. Think about the two things that we will always have, a keyboard and a mouse, or a way to emulate those two things. As an Access programmer, one of the first things we learn is how to create an event handler. Drag a command button onto a form and then create a handler for the OnClick event for that button (a mouse event triggers that). As a result, all serious VBA programmers understand events and event handlers. What very few VBA programmers understand is how to create our own objects which can sink as well as raise events.

John's discussion will teach you how to do just that. By the end of the night you will understand what events really are, why you use them, and how you use them. He has written a demo program to let you see, play, touch and feel events and the code that handles them. He will demonstrate how to:

1) Create your own classes.

2) How to sink events inside of your own classes.

3) How to make your own classes raise events.

4) How to ‘wrap’ an access object such as a form, text box, combo box or list box in your own class and then extend the functionality of those objects, make them better, make them do what you want them to do.

5) How to step through the code and watch the event handling unfold.

Everything you see and use in Access are classes. We can make our own classes. Let John show you how. Nope, not the ‘Cat says meow’ kind of class, that is boring.

Download the presentation files from your AUG Access Pacific Dashboard. (You may need to join the group and sign in.)

Please join us for our Monthly Chapter Presentation on September 7th, at 6:30PM Pacific Time Zone
(Please verify your Time Zone offset with World Time Buddy.)

We might even get an advanced look at a new book.

Access Pacific holds FREE Q&A webinars the First Thursday of every month, from 6:30 pm to 7:30 pm Pacific.

Add AUG Pacific meeting to your_Outlook Calender
 
Joined and downloaded. Looks really interesting.
 
I watched the replay on YouTube, that was a fun presentation. I can't wait for the next installment. This one presentation caused me to join the Pacific group so I could read through that 59 page book John wrote on the subject. Very impressive so far. Every time he talked about sinking events, I couldn't help but think "does he really mean sync events?". 😀

I learned some new terminology today. Sink, Sunk, and Raise. I've heard the term raise event, but haven't heard it explained quite the way John has in his book and the Sinking part was something I have seen in the VBE, but didn't understand in quite the way John explained. Very enlightening.
 
I watched the replay on YouTube, that was a fun presentation. I can't wait for the next installment. This one presentation caused me to join the Pacific group so I could read through that 59 page book John wrote on the subject. Very impressive so far. Every time he talked about sinking events, I couldn't help but think "does he really mean sync events?". 😀

I learned some new terminology today. Sink, Sunk, and Raise. I've heard the term raise event, but haven't heard it explained quite the way John has in his book and the Sinking part was something I have seen in the VBE, but didn't understand in quite the way John explained. Very enlightening.
I'm glad I brought the point up in the meeting. Experienced developers often talk about sinking events without explaining what that means. I thought John's explanation in his response made sense of it in a very accessible way.
 
I was really bummed I missed it live but just watched the youtube replay, which made me even more bummed I missed it live.

I use classes a lot . The problem with being self taught is you're never really sure you're doing it right and it's reassuring to see it explained and understand what's being talked about.

I'm going to keep my eye out for Part 2 of his presentation and hopefully catch it live. I've got questions!
 
I'm going to keep my eye out for Part 2 of his presentation and hopefully catch it live. I've got questions!
If you wouldn't mind sharing a few of your questions here just for the sake of discussion, it might be interesting. I don't have any questions yet because I'm too new to the whole thing. I'm just absorbing the concepts and going through his examples provided. I'm really curious what his supervisor class looks like (for his framework).

That analogy that he used for "Raising or sourcing" an event using a radio station broadcasting it's message or music made that part of the concept really easy to understand. As I read through his book, I'm noticing how profound some of his statements are. Take the following two paragraphs from pg. 10.

For now, just understand that only a combo can RAISE a combo event, only a command button can RAISE a command button event. To RAISE an event means that an OBJECT "broadcasts" an event that it knows how to RAISE.

You can SINK the combo event in any class, IF you have dimensioned a combo variable "WithEvents", and IF you have captured a pointer to said combo in the class module. You can even SINK the event on multiple class modules.
 
I've always wondered why we don't see more of this type thing.
4) How to ‘wrap’ an access object such as a form, text box, combo box or list box in your own class and then extend the functionality of those objects, make them better, make them do what you want them to do.

We often see questions where someone wants to open a pop up form and either retrieve info from the form or run code when the pop up is closed. Very often the solution offered is to open the popup as dialog pausing the code and continuing when the popup is closed, or call a public procedure in the main form. It Seems to me much simpler to just use a custom event. Another scenario is opening a form and passing info to it, a default value for instance. Often it is suggested to pass things in using openargs.

I've been using code like below which just seems so easy and developer friendly. This is a simple example but in most of them the custom close event code is much more complicated.

Code:
Dim WithEvents frmCloseCalEvents As Form

Private Sub btoAddEvent_Click()

    DoCmd.OpenForm "pfrmCaseCalendar", , , , acFormAdd

    Set frmCloseCalEvents = Forms("pfrmCaseCalendar")
    frmCloseCalEvents.OnClose = "[Event Procedure]"
  
    frmCloseCalEvents.CaseID.DefaultValue = Me.CaseID
    frmCloseCalEvents.Caption = Me.lblCaseCaption.Caption

End Sub

Private Sub frmCloseCalEvents_Close()

    Me.lstEvents.Requery
    Me.lstEvents = Null
  
    Set frmCloseCalEvents = Nothing

End Sub

In the above I'm opening a popup form and then setting a form variable pointing to the opened form. I then use that form variable to set a default value on the popup form and set a caption. You can also use the close event or some other event to retrieve data from the form variable such as - NewPrimaryKey = frmCloseCalEvents.EventID.

One question I had, but just tested for myself, was whether there would be any collisions between the native close event of the popup form and the close event of the form variable. It appears there isn't as the native event runs first and then the custom event. I assume this is because the form and form variable are 2 distinct objects.
 
I've always wondered why we don't see more of this type thing
Might want to follow me. I have written a lot on all of these subjects.


Addresses all
1) Create your own classes.

2) How to sink events inside of your own classes.

3) How to make your own classes raise events.

4) How to ‘wrap’ an access object such as a form, text box, combo box or list box in your own class and then extend the functionality of those objects, make them better, make them do what you want them to do.

5) How to step through the code and watch the event handling unfold.
 
Might want to follow me. I have written a lot on all of these subjects.


Addresses all
You get the credit for my "Aha" moment which was something you posted that made it all make sense to me. Then you posted a few challenges, some I could do, some I still don't get but I occasionally revisit them. I do read all your posts on the subject and go through your examples. If I knew half of what you know on the subject I'd be a happy man.
 
This addresses
Custom Collections
Default Properties
For Each Loops in custom collections

 
One question I had, but just tested for myself, was whether there would be any collisions between the native close event of the popup form and the close event of the form variable. It appears there isn't as the native event runs first and then the custom event. I assume this is because the form and form variable are 2 distinct objects.
That's good to know that there is no conflict there.

Might want to follow me. I have written a lot on all of these subjects.
I'll have to go through all of your info on the subject again. I'm just happy that John was able to get through my mental blocks for actually applying some of these idea's to my own projects. I'll definitely go through it again MajP.
 

Users who are viewing this thread

Back
Top Bottom