Access can't find function

B

Bill

I have a form with a sub-form in which I want
to include a VBA public function that is invoked
from a pop-up menu. I created the pop-up menu
and specified its name in the sub-form's properties.

I was expecting that when I right-clicked on the
sub-form that my function would receive control.
But, I get a runtime error indicating that Access
can't find the function. Does the public function
have to be in a general module? Code sheet of
the parent? Or what?

Thanks,
Bill
 
K

Klatuu

Not true. A public function can be in a form module. You have to qualify
the reference to the function to include the form name, but that is a really
bad idea.
 
B

Bill

Dave,
This is a very special case where the function ONLY
applies to the sub-form that invokes it. Since the
invocation is part of the pop-up properties, what
would that look like?

=MyForm!MyFunctionName()


Bill
 
K

Klatuu

Not for a subform. A form being used as a subform does not exist as a form.
It is a property of the subform control on the main form.

Since you posted this in a reports group, I assumed you were talking about
the open even of a report.

The code should be in the code module of the form being used as a subform.
Or it should be a Public function in a standard module.
 
B

Bill

This is a formscoding NG, so I don't understand your
comment regarding posting in the Reports NG.

The Function code IS in the code module of the form being used
as a subform. The question is one of syntax of the function
invocation as it appears in the property sheet of the custom
pop-up.

So far, I've tried =forms!MyParentFormName!MySubFormName!MyFunction()

But the runtime error persists and doesn't offer much help as to what's the
matter. I compiled in design mode, so there's no compiler errors reported
there.

Any suggestions?

Bill



Klatuu said:
Not for a subform. A form being used as a subform does not exist as a
form.
It is a property of the subform control on the main form.

Since you posted this in a reports group, I assumed you were talking about
the open even of a report.

The code should be in the code module of the form being used as a subform.
Or it should be a Public function in a standard module.
 
B

Bill

Well, let me see..................

Under normal circumstances, a pop-up menu would have
a function invocation like "=MyFunction(argument)" coded
in its "On Action" property, and the public function itself
would be coded in a general module.

The only reason I want the function to be in the code module
of the sub-form is that I need the function to have access to the
fields within the sub-forms RecordSource.

So, the question is what to code in the "On Action" property
of the pop-up menu so that the function can be found by
access when the function is in the code module of the sub-form.

Bill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top