Execution of click events in subforms through the parent form (1 Viewer)

aref

New member
Local time
Today, 12:18
Joined
Jan 10, 2023
Messages
27
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
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 07:18
Joined
May 21, 2018
Messages
8,605
Did you try
Chil1.form.cmd_project_click
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 06:18
Joined
Feb 28, 2001
Messages
27,320
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 )
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 12:18
Joined
Jul 9, 2003
Messages
16,364
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.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 07:18
Joined
Feb 19, 2002
Messages
43,484
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?
 

Isaac

Lifelong Learner
Local time
Today, 04:18
Joined
Mar 14, 2017
Messages
8,871
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
 

Isaac

Lifelong Learner
Local time
Today, 04:18
Joined
Mar 14, 2017
Messages
8,871
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 ........
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 06:18
Joined
Feb 28, 2001
Messages
27,320
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.
 

Isaac

Lifelong Learner
Local time
Today, 04:18
Joined
Mar 14, 2017
Messages
8,871
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
 

Isaac

Lifelong Learner
Local time
Today, 04:18
Joined
Mar 14, 2017
Messages
8,871
Reminds me of this thread, where someone was trying to have both events at once, I think NG enjoyed it a bit too much!

 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 12:18
Joined
Jul 9, 2003
Messages
16,364
I wrote a more detailed description of the issue in February 2022 here:-


I will eventually Blog this on my website!
 

Isaac

Lifelong Learner
Local time
Today, 04:18
Joined
Mar 14, 2017
Messages
8,871
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:
 

Isaac

Lifelong Learner
Local time
Today, 04:18
Joined
Mar 14, 2017
Messages
8,871
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

Top Bottom