Use passed formname in function

D

Depez

From a module I call a public function named Test with the name of a
form (named 'testformname') as a parameter
like this:
Test("testformname")

In the (public) test function I would like to use the passed var to
add items to a control named 'Control01'.

The function Test looks like:

public function test(Formvar)

Formvar.Control01.AddItem ("bla")
...
etc

The Formvar should be replaced by the value it contains.
So it would actually perform: testformname.Control01.AddItem ("bla")

This doesn't work but how do I get this to work?
I found some answers in different groups telling to define the var as
type form: public function test(Formvar as Form)
This doesn't work (error, form is an undefined type).

Thanks.
 
K

Karl E. Peterson

Depez said:
From a module I call a public function named Test with the name of a
form (named 'testformname') as a parameter
like this: Test("testformname")

Have you already created an instance of this form? IF so, pass that, not the form's
typename.
In the (public) test function I would like to use the passed var to
add items to a control named 'Control01'.

The function Test looks like:

public function test(Formvar)

Formvar.Control01.AddItem ("bla")
..
etc

The Formvar should be replaced by the value it contains.
So it would actually perform: testformname.Control01.AddItem ("bla")

This doesn't work but how do I get this to work?
I found some answers in different groups telling to define the var as
type form: public function test(Formvar as Form)
This doesn't work (error, form is an undefined type).

You'd probably want to use UserForm rather than Form, if this is VBA. But if you're
passing only the typename of the form, that won't work either. YOu could create a
new instance within the procedure, but that may or (most likely) may not help.
 

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