Event Order Reference that includes VBA exceptions or differences

JMongi

Active member
Local time
Today, 13:40
Joined
Jan 6, 2021
Messages
802
I have the following page bookmarked:


Is there a similar type of reference which incorporates the exceptions or differences when data is modified via VBA? (Edited for typos and clarity).
 
Last edited:
Unless you do something that affects the state of a form (like opening it or closing it or saving the record or triggering Maximize, Minimize, Restore), there are very few code-initiated steps that will trigger events. Single-control events typically don't fire based on VBA actions.
 
@The_Doc_Man - Quite true! Which is why I would like a nice reference that explicitly spells that out for me. :D

Microsoft and I don't always agree on what makes "sense". That's fine. It's their ball afterall. I just am looking for a nice copy of the rules of the game.
 
Hmmmm..... a sentence with "Microsoft" and "makes sense" in it.... I'll have to ponder that one.
;)
 
Control level events do not fire when you use VBA to modify data in the control.
@Pat Hartman - Is that universally true? Meaning there is precisely 0 form control event procedures that can be triggered via VBA data change?

Edit: Just to head things off at the pass, I am NOT meaning you can't use various tricks and work arounds to get Access to do what you want. I am focused very specifically on the idea of programmatically setting data in a form control i.e. FormControl.Value = Newdata.

P.S. The video was nice. Thanks!
 
There is nothing to stop you from doing that kind of value assignment. It just won't have any immediate side-effects due to events. Don't forget that using VBA you can do things to every data-centric control on a form. If you fired an event for each control change "behind the scenes" you would never get anything done. There is also this minor technical concept - that the only place where you can do a VBA change is already IN an event, and events cannot interrupt other events (with the sole exception of an "error event" - let's not go too deep on that one for now). Remember that for Access code, you DO NOT create a MAIN program, because MS Access IS the main program, whether we are talking about the full-out GUI and developer context or the run-time-only context. The only thing you CAN create is an event routine.

Stated another way, you don't need another event routine because you already are running one. Maybe that will help you see the logic of it.
 
No, NONE of the control events run when you set the value using VBA.
@Pat Hartman - Thank you. It seemed like it should be universal, I just couldn't find any MS documentation stating such. Also, I'm not trying to accomplish anything specific at the moment. Just looking for official reference material similar to the link in the first post.
 
Hi,
This question fits with what you are talking about Form to Form:
I've been looking for an event that gets fired when one closes the first form and then exits to the second form. Unfortunately, when I switch between the two open forms, the Deactivate event does NOT occurs for the first form, nor the Activate event for the second form. This is because the PopUp property is set to Yes for both forms and it will remain that way!

So back to my original question: Is there any event that gets fired? What is that event? I have been trying to find one that fits with no luck!

Marty
 
Look into WithEvents.

here's a basic example. Open form2 and type something then close form2.

In form1 there is a custom event which fires when form2 is closed and copies the text from form2 to form1
 

Attachments

I don't know is this has been explicitly mentioned, but changing data in a table using VBA is akin to modifying data directly at the table level. You can do pretty well whatever you want whether or not it makes sense, as long as it meets data validation rules.

Changing the value displayed in a text box on a form by using VBA is slightly different, as now you would have a dirty form, which I expect @Pat Hartman meant when she said how important the forms beforeupdate event is for data control.
 
You may not even need an event, per se, if switching between pop-up forms. Opening the 2nd form in dialog mode will pause the code in the 1st Pop-Up. We just need to know more about what your trying to accomplish.
 
How would I do that?
This describes how to create a custom event

Although you most definitely can create custom events for your form, you cannot create a new event that responds to a physical user form or control interaction (click, enter, exit, double click, etc.). Your event would more likely be data driven or a wrapper on multiple activities.
For example there is no "RightClick" event. However using the mouse down event and determining if it was button 2 I can raise a custom event called RightClick. That case is more like a wrapper of the mouse down event, although it would work like a RightClick event. The example in the link is a data driven event. If the data meets a condition an event is raised.

they did not provide this particular hook, therefore, you cannot add it
As written, the above statement is incorrect or at least not clear. I believe it means what I said previously, you cannot create a "hook" for a physical interaction. You can most certainly can create a "hook." For example see

This class turns any listbox and a group of command buttons into a sortable listbox where you can move items up and down. I simulate drag and drop using a series of events. I raise a custom "DragDrop" event that returns the index of the item dragged and the index of the item dropped. This however does not really react to the physical drag and drop, but instead is just a wrapper on a some other events and change in data. But once those activities that simulate "drag and drop" complete, I raise the event.

However, going back to this question
I've been looking for an event that gets fired when one closes the first form and then exits to the second form.
Would this simply be the same as the second form trapping when the first form closes?
 
Last edited:
Therefore, you cannot create an Event.
I do not know what to say since obviously you can create events. Raise those events and trap those events. This in not conjecture, but clearly something you can demonstrate.
This is not semantics. You might want to specify what you mean, but that blanket statement is incomplete.
If somehow a custom event is not an "event" in your opinion, please educate us on what the hell that means because I am surely clueless on your definition. Maybe it is like the sky is really not blue, but only our perception of the sky is. I guess.
 
You are suggesting that the OP create a FORM level Event that doesn't exist
Where in the @#$% did I say anything like that? You just make stuff up to support some non-existent argument. In fact I make no suggestion about anything the OP should or should not do. As I point out, I do not even understand why there is even an issue since you could simply trap the onclose event of any form. Why not read what I wrote, instead of telling me what I am suggesting.
OK, there are VBA constructs called "Events" but they are NOT form level events and so they are not triggered by the code that is actually running the form you know the code that MS wrote, and there is no way to raise one when focus (for lack of a better word) leaves a form because the code that is running the form, you know the code that MS wrote, didn't give us that event when the form is a popup.
So now you are trying to argue back to me what I already clearly stated. That's a new technique.
Although you most definitely can create custom events for your form, you cannot create a new event that responds to a physical user form or control interaction (click, enter, exit, double click, etc.).
You made the blanket statement that you cannot "create events", but we were somehow supposed to interpret that blanket statement to mean some very narrowly focused definition of
but they are NOT form level events and so they are not triggered by the code that is actually running the form you know the code that MS wrote, and there is no way to raise one when focus (for lack of a better word) leaves a form because the code that is running the form, you know the code that MS wrote, didn't give us that event when the form is a popup
You cannot now come back and specify what you meant, and say I am deliberately refusing to listen to your nonsense.
 

Users who are viewing this thread

Back
Top Bottom