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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Call a procedure on another form 2

Status
Not open for further replies.

metaltree

Technical User
Nov 27, 2006
28
CA
Is there a way to call from a first form (form1) a procedure written on a second form (form2)?
 
You can make it a Public procedure, if you're doing that then you may as well put the procedure in a module which allows easy access.

Hope this helps

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Okay. However, when I actually call that procedure on the second form, it sends me an error message:

Compilation error: undefined sub or function.

My code is as follows

On form 1:
Code:
Call abc

On form 2:
Code:
Public Sub abc()
(...code...)
End Sub
 
Harley gave you half an answer. Yes you need to make it public but you can not just call it by name.

ex:
Form name: Orders2
Procedure in form: testCall

How to call a procedure in a forms class.

Form_Orders2.testCall
or
forms("Orders2").testcall

not just
testCall
or
call testCall
 
If you move the subroutine to a module then your original way of calling it:

Call ABC

will work. It is a much better place to put the code if more than one form uses it.

 
Totally agree Joe [smile]

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
I agree, common code should go in a standard module. You can pass the code either a reference to the calling form or just the name of the calling form.

public sub commonRoutine(strFormName as string)
dim frmForm as access.form
frmForm = forms(strFormName)
.....
or simply

public sub commonRoutine(frmForm as access.form)
.....

call commonRoutine(me.name)
or
call commonRoutine(me)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top