Dynamic Calling of Subs

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Has anyone found a way of dynamically calling a controls, say after update
event.

Hard coded i would normally use:

ProjectName.Form_frmForm.txtControlName_AfterUpdate

I am after a way of replacing the form name and control event with variables.

Any help would be appreciated.
 
Andrew said:
Has anyone found a way of dynamically calling a controls, say after update
event.

Hard coded i would normally use:

ProjectName.Form_frmForm.txtControlName_AfterUpdate

I am after a way of replacing the form name and control event with variables.


You should not use the Form_formname syntax to refer to a
form instance. That syntax is used to refer to the form's
class, not to reference an instance of the form object.

If you only have one instance of the form open, then the
standard syntax is to use:
Forms!formname.procedurename args
or
Forms("formname").procedurename args
or
strfrm = "formname"
Forms(strfrm).procedurename args
or, if you prefer, you can use the Call statement
Call Forms(strfrm).procedurename(args)
(Note the important distinction of the parenthesis around
the arguments when you use Call.)

Remember that every public procedure in a form's module is a
method of that class and the syntax is the same as as
referencing any of its properties or methods.

If you have multiple instances of the forms, then you must
manage those instances with your own collection and use the
specific instance of the form object that you want to call.
 
Whatever for?
The form name can be captured using a variable:

strFrmName = Forms!frmSomeForm.Name

But now it is a string variable, not an object and can't be referred to as a
object.

I don't know that you can get the functions collection for an mdb. There is
an allfunctions property, but it applies only to SQL databases.

In any case, using variables to refer to functions makes absolutely no
sense. It would only make your code harder to read.

I would recommend you abandon the whole idea.
 
Using dynamic linking is an important method.

set obj = CreateObject("Access.Application")

v = loadlib("fred.dll")

Even in everyday use of my computer, sometimes I use
Word, and sometimes I use Notepad.

Sometimes it is desirable to dynamically link code inside your
own program. In an 'object oriented' design, you do this by
inheriting or over-riding methods. In a 'procedural' design, you
do this by using procedural variables. In a '1st Generation' design,
you do this by overwriting the procedural code. In a 'runtime'
or 'managed' design you do this by providing the name of the
function you wish to run to the object manager.

(david)
 
Back
Top