Sharing the same code

T

Techman

Dear friends,
I have some visual basic codes for my forms and my other forms also need to
use the same code, isn't there a way by which all the forms share the same
code.
The code is for the click event of the forms' field.
 
W

Wolfgang Kais

Hello Techman.

Techman said:
Dear friends,
I have some visual basic codes for my forms and my other forms
also need to use the same code, isn't there a way by which all
the forms share the same code.
The code is for the click event of the forms' field.

Create a new Public Sub in a standard module and paste the code here.
Replace all Me's by CondeContextObject.
Call the Sub from the event procedures in your forms.
 
M

Michael Kintner

Another method is to use another access database and put your code into
modules. Then add this access database as a reference in your references of
the original database. The references sets up an ability to share source
code calls and functions accross multiple databases that can be called by
different forms as well as different databases that have different forms.
Best of both worlds.

Mike (smile)
 
L

Linq Adams via AccessMonster.com

Whether these methods are practical, of course, is dependent on exactly what
kind of code you want to share! When speaking of sharing code between forms,
people frequently are talking about such things as moving to the
next/previous/first/last record, closing forms, etc. In a case like this,
because the shared code still has to be called from the appropriate event,
you're simply exchanging one line of code for another, which really doesn't
accomplish much!

Complex tasks that are done over and over again and whose execution requires
multiple lines of code obviously would bebefit from being in a public
function.
 
Top