Results 1 to 6 of 6

Thread: How can I call a Command button without clicking it?

  1. #1
    Join Date
    Jan 2009
    Posts
    22

    How can I call a Command button without clicking it?

    Hi,

    How can I call a Command button without clicking it?
    I want to execute a method but without the the user to click on the command Button!
    I want to know how is this possible to execute a method automatically without clicking it!
    How to code this thing?

  2. #2
    Join Date
    May 2008
    Posts
    2,012

    Re: How can I call a Command button without clicking it?

    You can call a click event anytime


    Code:
       1.      Option Explicit
       2.       
       3.      Private Sub Command1_Click()
       4.       Debug.Print "test"
       5.      End Sub
       6.       
       7.      Private Sub Form_Load()
       8.       Command1_Click
       9.      End Sub

  3. #3
    Join Date
    Jun 2008
    Posts
    144

    Re: How can I call a Command button without clicking it?

    Would OnTimer event be OK and with a condition that only allowd it to run once, as in when the form opens. Could be an unbound text box and the code makes and entry and the condition of the OnTime running is the text box is null....which it will be if you close and reopen the form.

  4. #4
    Join Date
    May 2008
    Posts
    35

    Re: How can I call a Command button without clicking it?

    Try this ...

    Code:
    1 Create a new form.
    
    2 Place a command button on the form (name it "cmdMyCommandButton").
    
    3 Put the following code into the command button's Click event -
    MsgBox "Here."
    
    (
    It should look like this -
    Private Sub cmdMyCommandButton_Click()
    MsgBox "Here"
    End Sub
    )
    
    4 Change "Private" to "Public" so it looks like this -
    Public Sub cmdMyCommandButton_Click()
    MsgBox "Here"
    End Sub
    
    5 Save and close the form (name it "Form1").
    
    6 Create a new module and in it a procedure like this -
    Public Sub DoIt()
    Form_Form1.cmdMyCommandButton_Click
    End Sub
    7 With the cursor within the procedure, click the "Run Sub" Toolbar icon ...
    a "Here" message should display.

    AND Try this.

    Change the code behind the Click event of your command button from, say,
    "Private Sub MyButton_Click()" to "Public Sub MyButton_Click()" then use the
    line following to execute the code from, say, a module -
    Form_MyForm.MyButton_Click (where "MyForm" is the name of your form)

    The form does NOT have to be open.

    You call the sub behind the command button with this line -

    Code:
    Form_frmFormName.cmdButton_Click
    where frmFormName is the name of the form containing the command button and
    cmdButton is the name of the command button.

    BUT FIRST YOU MUST change the clcik procedure behind the command button from
    Code:
    "Private Sub cmdButton_Click()" to "Public Sub cmdButton_Click()".

  5. #5
    Join Date
    Jan 2009
    Posts
    18

    Re: How can I call a Command button without clicking it?

    I have 2 forms (frmForm1 and frmForm2)
    frmForm2 has a command button called cmdButton
    How do i call the click event of cmdButton from frmForm1?

  6. #6
    Join Date
    Jan 2009
    Posts
    19

    Re: How can I call a Command button without clicking it?

    First of all define the command buitton as public
    and then call it form2.command1_click

    Suppose the command1_click is a private subroutine i don't think calling it as form2.Command1_click would help
    Hence it is it advisable to make it a public subroutine and the call it from another form

    OR

    Code:
    frmForm2.cmdButton =True

Similar Threads

  1. FIFA 13 won’t launch after clicking on play button
    By Cooper Sheldon in forum Video Games
    Replies: 3
    Last Post: 27-09-2012, 12:27 PM
  2. MSIsystem fails when clicking OC button in bios
    By X-MaaN in forum Overclocking & Computer Modification
    Replies: 6
    Last Post: 13-08-2011, 11:57 PM
  3. When clicking F11 button the top toolbars remain on the screen
    By Pracheth in forum Technology & Internet
    Replies: 5
    Last Post: 21-02-2011, 08:22 PM
  4. Stop Clicking on Farmville OK Button
    By Baasima in forum Video Games
    Replies: 5
    Last Post: 17-02-2011, 04:34 AM
  5. MOSS CPU is reaching 100 % when clicking on Submit button
    By Pappith in forum Windows Software
    Replies: 4
    Last Post: 15-04-2009, 07:33 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,854,194.58827 seconds with 17 queries