Wrapping controls WithEvents in classes (3 Viewers)

There is even a song to go with it. But I realize now I typed the quote wrong and should read "I've got mine"

And yes as @NauticalGent pointed out, super creepy and disturbing.
I like it better the way it is now. It expresses a certain je ne sais quoi.
 
I like it better the way it is now. It expresses a certain je ne sais quoi.
Actually I did have it correct, as @cheekybuddha said, it does say that quote in the last line of the song. Not that there was any "je ne sais quoi" thought put to this, I just copied something from the internet (top ten famous quotes from..)
I used to have Les Grossman from Tropic Thunder as my avatar until several people really thought it was me and said it was not a very flattering picture. So I went with this assuming no one really would really think it was me. Bizarrely that picture really does look like my dad without the big hair. Sorry for derailing this thread with my avatar discussion.
 
However all the form has at this time is the controls, no code? so that is not going to work?
You then ask to open ClsFrm and add a Close event and amend the Init event.
The first thing that you should notice is that the events of the class fire, displaying the
“Initialize” debug statement. Remember I said that unlike regular modules, classes have
two events that fire when they instantiate. We have created sinks in the class module to
sink these events and so the debug statement will execute when we instantiate the class.
 Close the form
Thanks for the book @jwcolby54, enjoying it. Obv's in the interest of constructive feedback I'd agree with @Gasman here. Up to p28 & as @Gasman mentioned p27 says that we are able to step through & fire the after_update events; which of course we haven't hooked up the main frm yet... & are not able to do this.

Again thanks for the book.
 
Thanks for the book @jwcolby54, enjoying it. Obv's in the interest of constructive feedback I'd agree with @Gasman here. Up to p28 & as @Gasman mentioned p27 says that we are able to step through & fire the after_update events; which of course we haven't hooked up the main frm yet... & are not able to do this.

Again thanks for the book.
@dalski And thank you for reading and commenting on it. I will go look at page 28 and fix it.

As you may have discovered, the book PDF is live out on GitHub.

But can you cut and past a small bit of the text into here so I can search for and find it?

I have switched from .odt to .Fodt, which is a "straight xml format" for the book I am writing in LibreEdit. I have no idea whether it may cause minor changes in the formatting or whatever.
 
Last edited:
Subject:
Can With Events Trigger AfterUpdate Across Forms in Access VBA?

Hi John, I’m working on a Microsoft Access VBA scenario and would love your expert opinion on whether With Events can help. Here’s the setup:

I have a calling form with a text box (txtBirthDate) for a person’s birthdate. Double-clicking this text box (or clicking a button) opens a date picker form. I pass the txtBirthDate control as an object to the date picker form, where it’s stored as an object variable (e.g., Private m_txtBirthDate As Access.TextBox). This creates a link, so updating the object variable in the date picker form updates the original txtBirthDate on the calling form.

When the user selects a birthdate in the date picker form, I want to update txtBirthDate and also calculate the person’s age to display in another text box (txtAge) on the calling form.

Logically, I’d trigger the AfterUpdate event of txtBirthDate to run the age calculation and update txtAge. However, I understand that programmatic updates to a control’s value don’t fire the AfterUpdate event, and I don’t believe it’s possible to trigger this event from another form.

I’m wondering if With Events could somehow be used to achieve this. For example, could the date picker form use With Events to trigger or simulate the AfterUpdate event of txtBirthDate?

I’m skeptical that this is possible, but given your expertise, I’d love to hear your thoughts!

Interestingly, while writing this, I had a breakthrough: I could pass both txtBirthDate and txtAge as object variables to the date picker form. When the user selects the birthdate, I can update m_txtBirthDate with the selected date and calculate the age to update m_txtAge directly, bypassing the AfterUpdate event entirely.

This seems promising, but I’d appreciate your feedback on this approach or any better alternatives using With Events or other techniques.

Thanks for your insights!

Uncle Gizmo - (Tony)
 
Tony,
So why not use the AfterUpdate event of the control on the date picker form to calculate the age and update what is needed?
 
Re:- Tony,
So why not use the AfterUpdate event of the control on the date picker form to calculate the age and update what is needed?

I think it would be better to use the date choosing process to update both the text object representing the date text box on the calling form and use the same process to update the age text box on the calling form...

The only issue with it is it adds extra code in the date picker form which is not useful for a normal date picking operations... So although it solves the problem it creates more!
 
You could just set the ControlSource of txtAge to:

=IIf(IsDate([txtBirthDate]), AgeFromDOB([txtBirthDate]), Null)

(where AgeFromDOB() is your function that calculates age)
 
@dalski cut and past a small bit of the text...

Thanks @jwcolby54, I was basing my experience on the most recent .pdf on this post. I see a lot of references to GitHub but have not found a link to it. My humble feedback is the second e.g. insinuates that the code will run, & is detailed in it's step by step process. But there are no references to hooking up the frmDemoCtls to the clsFrm.
Thanks again for the book. Stating the obvious any fool can critique a book, very few can write one. Merely trying to help (albeit a little):

p29 "You can prove that to yourself by deleting this text in some property of some form or control in an existing project, cause that event to fire, and notice that the code no longer runs in your code behind form. Put that text string back and notice that the event code now runs in your code behind form"
The code cannot run, it is not hooked up to external form yet. It gives the user the impression they have not set-up correctly with their code not running. When they have followed each step.

p31 " Save the class and open the form. The first thing that you should notice is that the events of the class fire, displaying the “Initialize” debug statement."

p33 - For Each ctl in mfrm.Controls
1749379523281.png
 
Last edited:
Thanks @jwcolby54, I was basing my experience on the most recent .pdf on this post. I see a lot of references to GitHub but have not found a link to it. My humble feedback is the second e.g. insinuates that the code will run, & is detailed in it's step by step process. But there are no references to hooking up the frmDemoCtls to the clsFrm.
Thanks again for the book. Stating the obvious any fool can critique a book, very few can write one. Merely trying to help (albeit a little):

p29 "You can prove that to yourself by deleting this text in some property of some form or control in an existing project, cause that event to fire, and notice that the code no longer runs in your code behind form. Put that text string back and notice that the event code now runs in your code behind form"
The code cannot run, it is not hooked up to external form yet. It gives the user the impression they have not set-up correctly with their code not running. When they have followed each step.

p31 " Save the class and open the form. The first thing that you should notice is that the events of the class fire, displaying the “Initialize” debug statement."

p33 - For Each ctl in mfrm.Controls
View attachment 120164
@dalski the actual live PDF can be found here:

EventDrivenProgrammingInVBA.pdf

And yes, I have been accused of writing like a drunken fireman spraying water from a firehose. Please do download that and please store a reference to the book somewhere.

I have a saved page reference in my browser, in my Colby Consulting folder of page references, which points out to my blog on this subject.

This is my old blog, directly. With a sidebar. Pointing to the book blog post directly

John Colby's blogspot
 
Ok, for those who could be interested, the link is actually https://jwcolby.blogspot.com/2025/05/the-book-event-driven-programming-in.html
This is a better link to all the sections.

Now John, I have a question. Please excuse my likely stupidness, but on Page 18 we are creating basInitClass and basInitClasses ?
It appears that I create basInitClass and the save it again as basInitClasses?, which I cannot do, unless I copy all the code to a new module.
Looking at your demo db, there is no basInitClass?

Could you elaborate on this please?
@Gasman I know you are done :cry: but the latest version has chapters now. If you have any comments on the new format I'd be all ears.
 

Users who are viewing this thread

Back
Top Bottom