Calling functions on a Form Class Object from a Module

S

Sullivan

Hey all

I've created a button on a form that calls all the buttons
on the form. However, Now I have to call the button from
outside the form, when the form isn't open (aka, the user
can't click on the button). Is there a way to do this?
 
D

Dirk Goldgar

Sullivan said:
Hey all

I've created a button on a form that calls all the buttons
on the form. However, Now I have to call the button from
outside the form, when the form isn't open (aka, the user
can't click on the button). Is there a way to do this?

You cannot call a procedure in a class module without creating an
instance of the class. That means the form *must* be open, even if
invisible, for you to call its procedures from ouside (and the
procedures you call must be Public). Yes, it's possible to create an
instance of the form, call its procedures, and close the instance, but
it seems likely that you can do what you want by moving the necessary
logic out of the form into a standard module and calling it there.

Would you care to explain what you're trying to do?
 
S

Sullivan

What I'm doing is creating an application that links to an
already created application that's based in VBA and
Access.

The current running application is a letter generator
based on the standardized paragraphs that are used to
create every letter in the building. Ex. Say a letter
was to go to an account holder about a rollover of money
into an IRA. There would be a paragraph with the (1)
explination of the rollover they've chosen, a paragraph on
(2)how much money, and a paragraph that the (3)money
broken down into how the total was comprised. Lastly,
would be the account holders (4)Address, Dear Ms./Mr. and
a (5)salutation. Each number above indicates a paragraph,
which would have a deptarment name and number in the
current application, that the program brings together and
puts into MS Word.

What the added application would do is call up a few of
the forms used at the get go of the program, input the
values and then, where before the letters would have areas
for a user to overwrite what's there so that the letter
had meaning, now, those things would be automatically
written over.

The powers that be do not want me to add anything
significant to the current application - they insist that
I make my application so that it locks into the current
one. Since there are several places where actions are
based on user inputs, there are buttons that the users use
to go different routes within the application. So, since
I need to do some of those functionalities, which were
programmed into the button clicks directly, I need to be
able to virtually click the buttons from the application
that I'm developing.

Brian
 
D

Dirk Goldgar

Sullivan said:
What I'm doing is creating an application that links to an
already created application that's based in VBA and
Access.

The current running application is a letter generator
based on the standardized paragraphs that are used to
create every letter in the building. Ex. Say a letter
was to go to an account holder about a rollover of money
into an IRA. There would be a paragraph with the (1)
explination of the rollover they've chosen, a paragraph on
(2)how much money, and a paragraph that the (3)money
broken down into how the total was comprised. Lastly,
would be the account holders (4)Address, Dear Ms./Mr. and
a (5)salutation. Each number above indicates a paragraph,
which would have a deptarment name and number in the
current application, that the program brings together and
puts into MS Word.

What the added application would do is call up a few of
the forms used at the get go of the program, input the
values and then, where before the letters would have areas
for a user to overwrite what's there so that the letter
had meaning, now, those things would be automatically
written over.

The powers that be do not want me to add anything
significant to the current application - they insist that
I make my application so that it locks into the current
one. Since there are several places where actions are
based on user inputs, there are buttons that the users use
to go different routes within the application. So, since
I need to do some of those functionalities, which were
programmed into the button clicks directly, I need to be
able to virtually click the buttons from the application
that I'm developing.

It's rather a difficult problem they've set you, since you *cannot* call
a procedure in a form module from outside that module unless the
procedure is declared as Public, which is not the default. So if you
really have to call these button-click procedures, you're almost
certainly going have to modify the current application at least to make
the relevant procedures public. If they'll let you do that, you could
conceivably automate a separate instance of Access to open that
application and do what you need to via automation. It might be better
to set a reference to that application and use it as an object and code
library. You'd probably have to add at least some functions to that
application to support its use in such a fashion. I've never tried to
do this, though, so I'm just speculating.

It seems to me it would be much easier if the relevant logic were
abstracted from the button-click routines and placed in a standard
module, in the original database or in an add-in that could be called
from both the old and the new application. However, I can understand if
your management won't let you make such a big change to the old
application. Without seeing the details of what you've got and what you
have to accomplish, I can't follow this line any farther.

Are you sure you can't just link to the old database and use its data,
while copying the relevant code in your new application? That would be
the simplest approach.
 

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