Results 1 to 11 of 11

Thread: [RESOLVED] Fire event in other form

  1. #1

    Thread Starter
    Fanatic Member mutley's Avatar
    Join Date
    Apr 2000
    Location
    Sao Paulo - Brazil
    Posts
    709

    Resolved [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

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Fanatic Member mutley's Avatar
    Join Date
    Apr 2000
    Location
    Sao Paulo - Brazil
    Posts
    709

    Re: Fire event in other form

    Quote Originally Posted by techgnome View Post
    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

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5
    Hyperactive Member
    Join Date
    Oct 2013
    Posts
    389

    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.

  6. #6

    Thread Starter
    Fanatic Member mutley's Avatar
    Join Date
    Apr 2000
    Location
    Sao Paulo - Brazil
    Posts
    709

    Re: Fire event in other form

    Quote Originally Posted by techgnome View Post
    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 ?

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Fire event in other form

    Quote Originally Posted by stum View Post
    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  9. #9
    Hyperactive Member
    Join Date
    Oct 2013
    Posts
    389

    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.

  10. #10

    Thread Starter
    Fanatic Member mutley's Avatar
    Join Date
    Apr 2000
    Location
    Sao Paulo - Brazil
    Posts
    709

    Re: Fire event in other form

    Quote Originally Posted by techgnome View Post
    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

  11. #11
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

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
  •  



Click Here to Expand Forum to Full Width