Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

run a procedure from a procedure in Access VBA

Status
Not open for further replies.

rxsims

Technical User
Jul 14, 2003
34
CA
Hi,

I am trying to run a procedure from within a procedure:
-------------------------------------
Private Sub Procedure1()

do task....

End Sub

-------------------------------------

Private Sub Procedure2_Click()

Run Procedure1 (this is the code I need)

End Sub
-------------------------------------

I can't seem to find this anywhere.
Thanks.
 
There are two things to work with here, Subs and Functions.

Subs do work and Functions return a value

Create a form with a command button called "cmdCallSub" and paste this code in. Then, step through, the code you should get the idea.

The part you are missing is what's inside the ( ) and you "Call" the sub, not "Run" it

Code:
Private Sub cmdCallSub_Click()

Dim iSomeNumber As Integer

iSomeNumber = InputBox("Enter a Number", "Double your Number")

iSomeNumber = CalledFromSub(iSomeNumber)

Call DisplayYourNumber(iSomeNumber)

End Sub

Private Function CalledFromSub(MyNumber As Integer)

CalledFromSub = MyNumber * 2

End Function

Private Sub DisplayYourNumber(MyNewNumber As Integer)

MsgBox "Here is your new number: " & MyNewNumber

End Sub
 
In addition if your subs are in different modules you need to declare them as Public rather than Private.
 
Thank you CaptainD and RivetHed.

I couldn't figure out "Call" needed to be used. My procedure works great now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top