|
-
Jun 29th, 2015, 08:23 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Fire event in other form
Hi
How can I to fill other forms and to fire some event (click eg) in other form
Tia
-
Jun 29th, 2015, 08:36 AM
#2
Re: Fire event in other form
Same app? Different app? We'd need some details... it depends on the situation. My first reaction on reading the title is - you don't. You put what you need to call into a friend or public method and call that from the places where you need to. But then I read the post... so now the answer changes depending on what you're doing.
-tg
-
Jun 29th, 2015, 08:47 AM
#3
Thread Starter
Fanatic Member
Re: Fire event in other form
 Originally Posted by techgnome
Same app? Different app? We'd need some details... it depends on the situation. My first reaction on reading the title is - you don't. You put what you need to call into a friend or public method and call that from the places where you need to. But then I read the post... so now the answer changes depending on what you're doing.
-tg
Hi thank you, is same application
I have a form A , have a grid with data , when the user change row I must to fill other form (same application ) Form B and validate data inserted by user in grid and to fire events Clicks some buttons
-
Jun 29th, 2015, 08:52 AM
#4
Re: Fire event in other form
Then do it like I mentioned... move the code you wish to execute to a firend sub and have the other form and the click event call it.
-tg
-
Jun 29th, 2015, 09:29 AM
#5
Re: Fire event in other form
Code:
Form1.Command1.Value = True
is what you're looking for.
if the control does not have a .value property, you can set the sub to public and call it from anywhere.
Code:
Public sub Command1_Click()
Msgbox "i'm a button"
End Sub
Code:
Private sub Form_Load()
Command1_Click
End Sub
Last edited by stum; Jun 29th, 2015 at 09:32 AM.
-
Jun 29th, 2015, 09:36 AM
#6
Thread Starter
Fanatic Member
Re: Fire event in other form
 Originally Posted by techgnome
Then do it like I mentioned... move the code you wish to execute to a firend sub and have the other form and the click event call it.
-tg
Sorry, but I did not understand
I have a Form A and Form B
In Form A I put a call sub (procedure) inside Form B
In Form B in Event (s) I build a call to Sub ?
-
Jun 29th, 2015, 10:12 AM
#7
Re: Fire event in other form
In form B:
Code:
Private sub SomeObject_Click)
MyClickHandler() 'That is all...
End Sub
public Sub MyClickHandler()
' do the stuff you would have put in the click event above
End Sub
From Form A:
Code:
FormB.MyClickHandler() 'Simple as that
-tg
-
Jun 29th, 2015, 10:16 AM
#8
Re: Fire event in other form
 Originally Posted by stum
Code:
Form1.Command1.Value = True
is what you're looking for.
if the control does not have a .value property, you can set the sub to public and call it from anywhere.
Code:
Public sub Command1_Click()
Msgbox "i'm a button"
End Sub
Code:
Private sub Form_Load()
Command1_Click
End Sub
While that's OK for some controls and events, personally I think it's a bad habit to get into. There can be unintended consequences. Especially the moment you decide that click event needs to also do something else, forgetting it's called from other locations where you DON'T want that second action to take place... Been there done that, got a collection of t-shirts. That's why the moment I find that event code needs to be called by a process outside the event, I move it to it's own dedicated sub and refactor as needed.
-tg
-
Jun 29th, 2015, 10:32 AM
#9
Re: Fire event in other form
I long ago stopped asking one-question-users the Why and focus more on the How, knowing that most of them likely will only come back to see a solution.
regarding this specific topic, in my personal opinion, placing a shared function on a module or a class would be a far more superior approach than calling it directly from the form.
may it be noted that in general, i'm against public code-snippets wondering on forms, from the get-go.
-
Jun 29th, 2015, 10:38 AM
#10
Thread Starter
Fanatic Member
Re: Fire event in other form
 Originally Posted by techgnome
While that's OK for some controls and events, personally I think it's a bad habit to get into. There can be unintended consequences. Especially the moment you decide that click event needs to also do something else, forgetting it's called from other locations where you DON'T want that second action to take place... Been there done that, got a collection of t-shirts. That's why the moment I find that event code needs to be called by a process outside the event, I move it to it's own dedicated sub and refactor as needed.
-tg
Thank you , I believe worked
-
Jun 29th, 2015, 10:52 AM
#11
Re: Fire event in other form
Also be aware that calling events in other forms can load the form if it was previously unloaded. This can result in your app staying loaded when your user closes the app because that now-loaded form was never unloaded.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|