Results 1 to 4 of 4
  1. #1
    mainerain is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Location
    Maine, USA
    Posts
    146

    vba to click button on another form


    Can't seem to get the right syntax to click a button on one form that opens another form and clicks Print button on the newly opened form

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    use the BUILDER to select the exact path to an item.
    but it will be like:

    'in form1
    docmd.openform "fMyForm2"
    forms!fMyForm2.btnPrint_click

    to open a specific record:
    docmd.openform "fMyForm2",,,"[Key]=" & txtKey

    MAKE SURE the button click event is PUBLIC
    Code:
    PUBLIC btnPrint_click()
    ...

  3. #3
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    Try:
    Code:
    DoCmd.OpenForm "[YourFormName]"Forms!YourFormName.SetFocus
    Call Forms.YourFormName.NameOfButton_Click
    You will need to replace YourFormName with, yes you guessed, the name of your form.
    Also replace NameOfButton

    You will also need to make the button OnClick procedure Public instead of Private

    EDIT:
    Sorry, got distracted and didn't realize that ranman256 had already replied
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  4. #4
    mainerain is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Location
    Maine, USA
    Posts
    146
    That's it! Thanks

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

Similar Threads

  1. Call a button click from another form
    By Rgaming in forum Access
    Replies: 3
    Last Post: 10-16-2017, 12:54 PM
  2. Pass Parameter To Form From Button Click
    By jo15765 in forum Forms
    Replies: 7
    Last Post: 08-16-2017, 01:31 PM
  3. Replies: 7
    Last Post: 11-03-2015, 02:43 PM
  4. run button countinous form with one click
    By adilos in forum Access
    Replies: 27
    Last Post: 08-11-2014, 05:27 PM
  5. On Click Event For Button On Form
    By Desstro in forum Forms
    Replies: 3
    Last Post: 08-09-2010, 02:36 PM

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