Running a form module from a second form

  • Thread starter Thread starter Seth Schwarm
  • Start date Start date
S

Seth Schwarm

I am attempting to to run a module written in one form
from a second, different form.

Here is my general example:

Form1

Form2

Public Sub HelloWorld() (a module of Form1 which is
simply a message box saying "Hello World" as a test)

In Form2 code I type:

Call Forms.Form1.HelloWorld

I get Run-time error 438. Object doesn't support this
property or method.

The crazy thing is that have used this method of calling
much more complex procedures in other applications I have
written, and they work great. I even went to these
applications and ran the code which makes these Call
statements and the code worked flawlessly.

All help is appreciated,

Seth
 
Make sure the Private keyword is removed from the target procedure. Use
Public or Friend instead.

Then call it with :
Call Form_Form1.HelloWorld
The "Form_" bit is important: it is the name that Access uses for the module
of Form1, as displayed in the Title bar of the code window when editing the
HelloWorld procedure.
 
Allen, you are the man!

Why does code I have written in the past work according
to the method I described in this email? The current
database I had this problem in is the same as one of the
old ones I have written: Access 2000 file format in
Access XP


How can the code work in one application and not another
when I am using the same version of Access on the same
physical machine?

Thanks,

Seth
 
Seth said:
I am attempting to to run a module written in one form
from a second, different form.

Here is my general example:

Form1

Form2

Public Sub HelloWorld() (a module of Form1 which is
simply a message box saying "Hello World" as a test)

In Form2 code I type:

Call Forms.Form1.HelloWorld

I get Run-time error 438. Object doesn't support this
property or method.


I'm not sure, but I think Call expects a procedure name
instead of an object reference. It might even be that the
Call statement requires the parenthesis:
Call Forms.Form1.HelloWorld()
but I also think that syntax is ambiguous. I never use Call
so I'm not up to speed on all its nuances.

Regardless of what I think, this syntax will work:
Forms.Form1.HelloWorld

The Form_ syntax that Allen suggested is another way to do
this and will work even if the form is not open. But, if
you should ever get into a situation where you want to do
this and have multiple instances of the form open and the
procedure uses static variables or the Me object, then Form_
will not work because you can not specify which instance
you're referencing. In this case (obscure albeit) use

Dim frm As Form
. . .
frm.HelloWorld

The key to all this is that a form module is a class module
and its Public procedures are methods of the class.
 
Back
Top