Public Function to call private (public) sub?

J

JHK

Is it possible to use in a Public Function a method to "call" a private sub
(or public sub) which is tied to a click_event on a form button?

I have a unique need to try this method, which would theoretically work as
follows:

1. User clicks buttonA on a form, which looks up certain information
(through a Public Function) based on the button.caption, then
2. As a part of Function statements in step1, "calls" a private sub which
is tied to a click event on another button (same form) called Add_Click.
3. Button Add_Click does lots of additional look ups and data manipulation.
(Button Add_Click also does things independent of the function that I would
create; therefore, this is why I haven't elected to re-write the entire
process.)

I tried just "calling" the private sub (and also renaming it as a public
sub) but the function reports that the sub is not declared.

Is this possible to accomplish in this manner?
 
D

Dirk Goldgar

JHK said:
Is it possible to use in a Public Function a method to "call" a
private sub (or public sub) which is tied to a click_event on a form
button?

I have a unique need to try this method, which would theoretically
work as follows:

1. User clicks buttonA on a form, which looks up certain information
(through a Public Function) based on the button.caption, then
2. As a part of Function statements in step1, "calls" a private sub
which is tied to a click event on another button (same form) called
Add_Click.
3. Button Add_Click does lots of additional look ups and data
manipulation. (Button Add_Click also does things independent of the
function that I would create; therefore, this is why I haven't
elected to re-write the entire process.)

I tried just "calling" the private sub (and also renaming it as a
public sub) but the function reports that the sub is not declared.

Is this possible to accomplish in this manner?

The sub Add_Click must be declared as Public, rather than Private, and
calls to it from outside the form containing it must be prefixed with a
reference to the form itself, as in:

Call Forms!Form1.Add_Click
 
J

JHK

I tried the Call Forms!.... statement, which in my case is:

Call Forms!frmAirportIDSelect.ClickAddtoItinerary

but I get an error stating, "Compile Error. Expected . or )"

I've tried enclosing in brackets and different formatting options, but
nothing successful yet.
 
J

JHK

Got it. It was this way:

Call Forms("frmairportidselect").clickAddtoItinerary_Click

Thanks for your help.
 
D

Dirk Goldgar

JHK said:
I tried the Call Forms!.... statement, which in my case is:

Call Forms!frmAirportIDSelect.ClickAddtoItinerary

but I get an error stating, "Compile Error. Expected . or )"

I've tried enclosing in brackets and different formatting options, but
nothing successful yet.

I thought you said the sub you wanted to call was "Add_Click". What is
"ClickAddtoItinerary"? Is it the name of a sub that is defined in the
code module of frmAirportIDSelect? If so, please post the Sub line
defining it.
 
D

Dirk Goldgar

JHK said:
Got it. It was this way:

Call Forms("frmairportidselect").clickAddtoItinerary_Click

Forms("frmairportidselect") is the same as Forms!frmairportidselect.
The problem was you were specifying the name of the button, not the name
of its Click event procedure. I'm glad to see you got it working.
 
J

JHK

sorry for the confusion.

It's Add_Click

So it's: call forms!frmairportidselect.add_click

I guess in my hasty excitement I got carried away with the typo (both in the
code and in the reply).

Thanks again.
 
D

David C. Holley

If there's a lot of code in the Add_Click(name?) sub. I would spin it
out to a public module. Then its just a matter of using Call
ProcessRecord or whatever the subs name is.
 

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