Using the Immediate window to run a sub

  • Thread starter new2access123 via AccessMonster.com
  • Start date
N

new2access123 via AccessMonster.com

I am just learning VBA and learning to use the debug features as I go. I
have successfully written functions and debugged then by running them from
the debug window.

?MyFunction()

In the Code Window I can position the cursor and press F5 and run the code
from that point.

Now I want to run a sub from the Immediate window. After some searching I
found that the correct syntax is to run my sub:

form_form1.Combo0_Click

But in the Code Window when I can position the cursor and press F5 to run the
code from that point a Macro dialog shows up for me to select a function
from a completely different module.

What is VBA doing?
Is there an equivalent to the F5 feature that I can use in this case?

Thanks
 
S

Stuart McCall

new2access123 via AccessMonster.com said:
I am just learning VBA and learning to use the debug features as I go. I
have successfully written functions and debugged then by running them from
the debug window.

?MyFunction()

In the Code Window I can position the cursor and press F5 and run the code
from that point.

Now I want to run a sub from the Immediate window. After some searching I
found that the correct syntax is to run my sub:

form_form1.Combo0_Click

But in the Code Window when I can position the cursor and press F5 to run
the
code from that point a Macro dialog shows up for me to select a function
from a completely different module.

What is VBA doing?
Is there an equivalent to the F5 feature that I can use in this case?

Thanks

F5 starts your app from ground 0, it doesn't 'run code from that point'. Try
typing:

form_form1.Combo0_Click

into the immediate window, then press Enter.
 
N

new2access123 via AccessMonster.com

thanks. I miss undrestood where F5 starts.

Stuart said:
I am just learning VBA and learning to use the debug features as I go. I
have successfully written functions and debugged then by running them from
[quoted text clipped - 19 lines]

F5 starts your app from ground 0, it doesn't 'run code from that point'. Try
typing:

form_form1.Combo0_Click

into the immediate window, then press Enter.
 
D

Douglas J. Steele

Actually, from the name of your routine, it sounds as though it's an Event
Procedure associated with a combo box on form Form1. Event Procedures for
controls are declared as Private by default, so you won't be able to run it
from the Immediate Window unless you change the declaration from Private Sub
Combo0_Click() to Public Sub Combo0_Click()

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



new2access123 via AccessMonster.com said:
thanks. I miss undrestood where F5 starts.

Stuart said:
I am just learning VBA and learning to use the debug features as I go. I
have successfully written functions and debugged then by running them
from
[quoted text clipped - 19 lines]

F5 starts your app from ground 0, it doesn't 'run code from that point'.
Try
typing:

form_form1.Combo0_Click

into the immediate window, then press Enter.
 
N

new2access123 via AccessMonster.com

I am nit sure i know what you mean that a private sub can not be run from the
immediate window? the sub is defined as:

Private Sub Combo0_Click()

When I enter:

form_form1.Combo0_Click

in the immediate window it runs the sub.
Actually, from the name of your routine, it sounds as though it's an Event
Procedure associated with a combo box on form Form1. Event Procedures for
controls are declared as Private by default, so you won't be able to run it
from the Immediate Window unless you change the declaration from Private Sub
Combo0_Click() to Public Sub Combo0_Click()
thanks. I miss undrestood where F5 starts.
[quoted text clipped - 12 lines]
 
D

Douglas J. Steele

Hmm. I'm surprised. I thought you could only do that if the sub was defined
as Public.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



new2access123 via AccessMonster.com said:
I am nit sure i know what you mean that a private sub can not be run from
the
immediate window? the sub is defined as:

Private Sub Combo0_Click()

When I enter:

form_form1.Combo0_Click

in the immediate window it runs the sub.
Actually, from the name of your routine, it sounds as though it's an Event
Procedure associated with a combo box on form Form1. Event Procedures for
controls are declared as Private by default, so you won't be able to run
it
from the Immediate Window unless you change the declaration from Private
Sub
Combo0_Click() to Public Sub Combo0_Click()
thanks. I miss undrestood where F5 starts.
[quoted text clipped - 12 lines]
into the immediate window, then press Enter.
 
S

Stuart McCall

Douglas J. Steele said:
Hmm. I'm surprised. I thought you could only do that if the sub was
defined as Public.
<snip>

You can do it if the form_ syntax is used, I assume because that makes it a
public property of the form. Incidentally (for anyone reading this) be aware
that such code will execute whether the form is 'open' or not. If not, then
it's loaded in a hidden state first.
 
S

Stuart McCall

Stuart McCall said:
<snip>

You can do it if the form_ syntax is used, I assume because that makes it
a public property of the form. Incidentally (for anyone reading this) be
aware that such code will execute whether the form is 'open' or not. If
not, then it's loaded in a hidden state first.

I meant public method, not public property.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top