Results 1 to 12 of 12
  1. #1
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839

    Link event to another form

    Say I have 2 forms developed

    Form.Start and Form.Stop

    Both can email the same form. I have a report open button and an email form button. When I select the Open form button, I also have an email button on the report itself.

    I have duplicate VBA code in the report and the form.start doing the same email. How can I link the button in the report to the Form.start email button?

    If I select the email button to edit the [Event Procedure] it takes me automatically to the report's VBA, I would like to link it to the forms VBA code.

    Gracias

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You can make the form event public and call it from the report, but personally I'd create a public function and call it from both.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,407
    The report must have its own code module. The Button_onclick event must be in that module.
    It the FORM name is formStart and the button on that form is named SendEmail
    Then the code for the REPORT button on_click event should be
    Call FORM_formStart.SendEmail

    Form formStart must be loaded for this to work.
    UpRider

  4. #4
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    pbaldy,
    How do I make this "Public" other than changing the name from Private Sub?

  5. #5
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Just change Private to Public.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    It can't be as easy as that. I have to do that on both the report and the form? Do I need to have some sort of centralized place? Do I leave all the code in one and just the Public Sub_Send_Email_Click()?

  7. #7
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    So you didn't try? Change Private to Public in the form. In the report:

    Forms!FormName.ButtonName_Click

    But as mentioned that requires the form to be open, which is why I'd use a public function called by both.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    Pbaldy,
    I did change it, I was a bit surprised of the simplicity on that part.

    Whare do I put the "Forms!FormName.ButtonName_Click" I have tried it in the report under the select button on click event = Form!Start.Send_Open_Click. I have also tried putting it in the Buttons' name, and in the reports VBA under the Private Sub Send_Open_Click()

  9. #9
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    I think I have found it.
    Seems to work on one form/report set
    The other doesn't....yet

    Report
    Private Sub Send_Open_Click()
    Call Form_Start.Send_Open_Click
    End Sub

    Form Change Private to Public

  10. #10
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    So you've got it working?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    Yes I did! Thanks pbaldy. I'll mark as solved.

  12. #12
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 13
    Last Post: 09-10-2015, 03:37 PM
  2. Replies: 12
    Last Post: 03-16-2015, 04:57 PM
  3. Replies: 7
    Last Post: 05-08-2014, 10:34 AM
  4. Replies: 1
    Last Post: 03-29-2014, 07:46 PM
  5. Replies: 7
    Last Post: 08-28-2013, 02:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums