Execution of click events in subforms through the parent form

aref

New member
Local time
Today, 05:05
Joined
Jan 10, 2023
Messages
28
Hello
I encountered a problem to refer the events in the forms.

In the Frm_Main form, I have a subform called Child1, now I want the double click event of the cmd__ProjectA button
run (cmd__ProjectA_DblClick)

And on the other hand, I have another subform in child1 called chlid2 that I want to have the cmd_Project button click event as well. (cmd_Project_Click)

Please guide according to the attached sample.

Thanks
 
Did you try
Chil1.form.cmd_project_click
 
MajP gave you an answer, but I think I need to amplify a bit. He wasn't wrong about the single-click case, but there is a wrinkle for double clicks.

First, just to clarify why that works, the syntax involves the name of the sub-form control (NOT the name of the actual sub-form):

Code:
subformcontrol.Form.Cmd_Project_Click

Second, for double-clicks, there is a Cancel argument that would be automatically coded into the entry-point declaration. You must therefore supply the correct call or you would get a "wrong number of arguments" error.

Code:
Dim CancelArg as Integer

...

subformcontrol.Form.cmd_ProjectA_DblClick( CancelArg )
 
It is not a good idea to call click events. It's far better to transfer the code out of the click routine into its own routine and call the new/separate routine from the click event and from anywhere else you desire.
 
YOU cannot, using code cause a windows event to fire. So you cannot actually, with code, "click" a button or a control and cause the button to depress and run it's click event. You can however, call the procedure executed by that click event to run the code. BUT, you are misusing the form events. If you have code that needs to run from the click event of a form/subform and also when you call it, then the professional solution is to isolate the code into its own procedure and call it from each event. That makes everything crystal clear. You will ALWAYS know that the code is used in more than one situation so if you need to change it, you will KNOW that you need to be aware of the other situations when the event is called.

Logically, there is something wrong with what you are attempting to do. Perhaps you could share with us, why you want to run the click( or dbl-click) event of a subform control from a button on the main form?
 
Agreed.

Anytime I have gotten to the point in my code where I find myself starting to write code to force/call other standard Form or Button events, I eventually admit to myself I have made some mistakes. Look for them and approach it differently
 
I have to add further, @aref , You may want to ponder the essence of the concept of having both a click and a double click event attached to a Button ........
 
I have to add further, @aref , You may want to ponder the essence of the concept of having both a click and a double click event attached to a Button ........

Good point, Isaac, since the difference between a click and a double click is controlled by an external Windows "click sensitivity" setting that could easily turn one double-click into two fast but distinct single clicks.
 
One could definitely spend quite a bit of time scratching one's head with both events, wondering why the double click event never occurs ... :p
 
Reminds me of this thread, where someone was trying to have both events at once, I think NG enjoyed it a bit too much!

 
I wrote a more detailed description of the issue in February 2022 here:-


I will eventually Blog this on my website!
 
I wrote a more detailed description of the issue in February 2022 here:-


I will eventually Blog this on my website!
Now you sound like Daniel ... :ROFLMAO:
 
I was referring to a recent ruckus in the Access forums that Daniel observed and then blogged about. If you can call a few sentences a blog article. Anyway. Didn't really mean much by it in any direction or another.
 

Users who are viewing this thread

Back
Top Bottom