PC Review


Reply
Thread Tools Rate Thread

How to activate command button on form by macro

 
 
Denis
Guest
Posts: n/a
 
      24th Oct 2008
I'm working on a macro to load, fill out, and run a form. I think I
know how to do everything except run the form. By run the form I mean
"click" the OK command button.

Here's basically what I have (in the same workbook as the form):

Load MyForm
MyForm.textbox = "some text"
MyForm.OKbutton.SetFocus
Application.SendKeys "{ENTER}"

I thought I could set the focus to the OK command button and send the
ENTER key but that isn't working. Should this work or is there some
other way to click the OK command button?

Denis
 
Reply With Quote
 
 
 
 
Jim Thomlinson
Guest
Posts: n/a
 
      24th Oct 2008
By default when you created the OKbutton the click event procedure will be
private so it will look something like...

Private OKbutton_Click()

This means the the procedure is not exposed outside of the form. To expose
it you just need to change it to Public

Public OKbutton_Click()

Now you can call it like this...
call MyForm.OKbutton_Click()

You do not need to load the form. In fact that will halt the execution
waiting for user input on the form.
--
HTH...

Jim Thomlinson


"Denis" wrote:

> I'm working on a macro to load, fill out, and run a form. I think I
> know how to do everything except run the form. By run the form I mean
> "click" the OK command button.
>
> Here's basically what I have (in the same workbook as the form):
>
> Load MyForm
> MyForm.textbox = "some text"
> MyForm.OKbutton.SetFocus
> Application.SendKeys "{ENTER}"
>
> I thought I could set the focus to the OK command button and send the
> ENTER key but that isn't working. Should this work or is there some
> other way to click the OK command button?
>
> Denis
>

 
Reply With Quote
 
Denis
Guest
Posts: n/a
 
      24th Oct 2008
On Oct 24, 1:09 pm, Jim Thomlinson <James_Thomlin...@owfg-Re-Move-
This-.com> wrote:
> By default when you created the OKbutton the click event procedure will be
> private so it will look something like...
>
> Private OKbutton_Click()
>
> This means the the procedure is not exposed outside of the form. To expose
> it you just need to change it to Public
>
> Public OKbutton_Click()
>
> Now you can call it like this...
> call MyForm.OKbutton_Click()
>
> You do not need to load the form. In fact that will halt the execution
> waiting for user input on the form.
> --
> HTH...
>
> Jim Thomlinson


Thanks. I wondered if that was the right approach or if there was a
better or right way to do this.

Denis


> "Denis" wrote:
> > I'm working on a macro to load, fill out, and run a form. I think I
> > know how to do everything except run the form. By run the form I mean
> > "click" the OK command button.

>
> > Here's basically what I have (in the same workbook as the form):

>
> > Load MyForm
> > MyForm.textbox = "some text"
> > MyForm.OKbutton.SetFocus
> > Application.SendKeys "{ENTER}"

>
> > I thought I could set the focus to the OK command button and send the
> > ENTER key but that isn't working. Should this work or is there some
> > other way to click the OK command button?

>
> > Denis


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
macro attached to command button - VBA form Roy Gudgeon Microsoft Excel Misc 2 16th Mar 2010 12:44 PM
Excel macro or command button to search using a user form cvw Microsoft Excel Programming 1 9th Feb 2010 08:02 PM
Command Button on Form Macro Emily Microsoft Access 0 6th Dec 2007 06:31 PM
Re: Macro to activate form button kkknie Microsoft Excel Programming 1 11th May 2004 08:31 PM
How do you activate a "COMMAND Button" with a macro? RBB Microsoft Access Forms 3 7th Jul 2003 05:21 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:02 PM.