Run Sub in VBA

  • Thread starter Thread starter szag via AccessMonster.com
  • Start date Start date
S

szag via AccessMonster.com

I am having a problem using the "Run Sub" selection from the "Run" menu in
VBA. Each time I choose it a Macro dialog box pops up. My "step into" from
the Debug menu also doesn't do anything. I have tried to find the answer
through other questions on this site but can't find anything that tells me
why this seems to be disabled/not working right.
 
Is the sub a public sub?
Does the Sub have any arguments?

Sub doSomething() will run if the cursor is in the sub

Sub doSomething(strValue) will not run if the cursor is in the sub and
Access will display the "macro" dialog box.

--
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
Here is the code...

Private Sub Form_Load()
DoCmd.Maximize
Me.subTransDept.Visible = False
Me.subUnits.Visible = False
End Sub


It works fine, but when I try to run it in the editor (F5) I just get the
macro dialog box.
 
It works fine, but when I try to run it in the editor (F5) I just get the
macro dialog box.


For forms code, you can NOT use f5 to run any event code. The f5 only works
for standard module code. The form has to be loaded and running (I believe
the same also applies to class objects).

in these cases if you really must single step through the forms loading code
at that point or see that code step by step I use the just put in a stop
command:

eg:

Private Sub Form_Load()
stop <--- put this in..and then remove when done testing
DoCmd.Maximize
Me.subTransDept.Visible = False
Me.subUnits.Visible = False
End Sub

You can also click in the side bar..and a red dot will appear..and that also
sets a break point.

You can call the code from the debug window *IF* YOU make the sub public

eg:
change:
Private Sub Form_Load()
to
Public Sub Form_Load()

Now, after the form is loaded, you can hit ctrl-g (debug window), and go:

Call forms!NameOfForm.Form_Load
 
Thanks!
For forms code, you can NOT use f5 to run any event code. The f5 only works
for standard module code. The form has to be loaded and running (I believe
the same also applies to class objects).

in these cases if you really must single step through the forms loading code
at that point or see that code step by step I use the just put in a stop
command:

eg:

Private Sub Form_Load()
stop <--- put this in..and then remove when done testing
DoCmd.Maximize
Me.subTransDept.Visible = False
Me.subUnits.Visible = False
End Sub

You can also click in the side bar..and a red dot will appear..and that also
sets a break point.

You can call the code from the debug window *IF* YOU make the sub public

eg:
change:
Private Sub Form_Load()
to
Public Sub Form_Load()

Now, after the form is loaded, you can hit ctrl-g (debug window), and go:

Call forms!NameOfForm.Form_Load
 
Back
Top