INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Jobs from Indeed

Call a procedure on another form

Call a procedure on another form

(OP)
Is there a way to call from a first form (form1) a procedure written on a second form (form2)?

RE: Call a procedure on another form

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: How to get the best answers before posting.

RE: Call a procedure on another form

(OP)
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

RE: Call a procedure on another form

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  
   

RE: Call a procedure on another form

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.

RE: Call a procedure on another form

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: How to get the best answers before posting.

RE: Call a procedure on another form

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)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close