Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • 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!

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

Donate Today!

Do you enjoy these
technical forums?
Donate Today! Click Here

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

metaltree (TechnicalUser)
22 May 08 9:22
Is there a way to call from a first form (form1) a procedure written on a second form (form2)?
HarleyQuinn (Programmer)
22 May 08 9:26
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.

metaltree (TechnicalUser)
22 May 08 9:54
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
Helpful Member!  MajP (TechnicalUser)
22 May 08 9:58
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  
   
JoeAtWork (Programmer)
22 May 08 12:06
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.

HarleyQuinn (Programmer)
22 May 08 12:08
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.

MajP (TechnicalUser)
22 May 08 12:38
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)

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!

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