Hi
How can I to fill other forms and to fire some event (click eg) in other form
Tia
Printable View
Hi
How can I to fill other forms and to fire some event (click eg) in other form
Tia
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
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
is what you're looking for.Code:Form1.Command1.Value = True
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
In form B:
From Form A: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
Code:
FormB.MyClickHandler() 'Simple as that
-tg
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
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.
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.