Using Call to access anouther Subroutine

entrist

Registered User.
Local time
Today, 04:23
Joined
Jul 7, 2010
Messages
10
Hey Guys and Gals,

I have looked on numerous search engines and i have found nothing that can help me.

I have two forms inside a tabbed form.

Tabbed form is called frmTab
Form1 is called frmForm1
form2 is called frmForm2 with the public sub TestCall

I am trying to make a subroutine work in Form2 with a variable and as i am constructing this module i have come across a problem. I cannot call frmForm2 from frmForm1. It will just not find it... can anyone help

Code:
Public Sub btnTestCall_Click()
Call Forms!frmTab!frmForm2.TestCall 'Gives Error use only . and ( whilst highlighting the !)
' i have also tried:
'Call Forms.frmTab.frmForm2.TestCall
'Call TestCall
'Call Forms.frmForm2.TestCall

End Sub

Code i am trying to access
Code:
Public Sub TestCall()
Me.txtTestCall.Value = "WELL DONE!"
End Sub

All ways give me errors.

Please help
 
With the sub defined as a Public sub, to call the sub routine in the other form just use:

TestCall

You really would not have to use the sub at all. It the other is open you can simply set the value of the control by using the complete reference to the form and the control:

Forms!frmForm2.TestCall = "WELL DONE!"
 
This:
Code:
Call Forms!frmTab!frmForm2.TestCall
to become this:
Code:
Call Me.Parent!frmForm2.Form.TestCall
 
Thank you both for the quick reply, however the issue is not resolved.

You really would not have to use the sub at all. It the other is open you can simply set the value of the control by using the complete reference to the form and the control:

Forms!frmForm2.TestCall = "WELL DONE!"

I have tried just refering to the sub publically, but i think as it is inside a form, it does not connect to it and i get a cannot find error.

This:
Code:
Call Forms!frmTab!frmForm2.TestCall
to become this:
Code:
Call Me.Parent!frmForm2.Form.TestCall

Both Options include the "!" bang, it gives me a syntax error when i use the Bang in both cases. When i change the ! for a . it give an error, 2452 run time

Thanks again
 
What do you mean both options include the bang?

It is simply:
Code:
Call Me.Parent![COLOR=Red]NameOfSubformControl[/COLOR].Form.TestCall
The only thing that needs amending is the bit in red. NameOfSubformControl should be the name of the control in which the form is embedded. Not the name of the form in the Source Object, but the name of the subform control.

To get the name of the subform control, click the subform ONCE and look in the Name property.
 
What do you mean both options include the bang?

It is simply:
Code:
Call Me.Parent![COLOR=Red]NameOfSubformControl[/COLOR].Form.TestCall
The only thing that needs amending is the bit in red. NameOfSubformControl should be the name of the control in which the form is embedded. Not the name of the form in the Source Object, but the name of the subform control.

To get the name of the subform control, click the subform ONCE and look in the Name property.

Thanks for the response, I was refering to the "!". Using ! after the call function gives me an error when inputting it in,

Code:
Call Me.Parent[COLOR=Red]![/COLOR][COLOR=Black]NameOfSubformControl[/COLOR].Form.TestCall

Code:
Compile Error:
Expected: . or (
then when i run the sub it gives me a syntax error

I have tried to replace the ! for a . and it doesnt help.

Thank you again
 
Oops yes, that's right. It should have been a dot.

So when you change it to a dot what is the full error message?
 
Oops yes, that's right. It should have been a dot.

So when you change it to a dot what is the full error message?

Code:
Run-Time Error "2452"

The Expression You Have Entered Has An Invalid Reference To The Parent Property.
Do I need to refence the Tab Form it is located in?
Thank you
 
The error message indicates that the form you're calling the function from is not a subform. So let's get some clarity on a few things.

Tabbed form is called frmTab - is a tab control and not a form?
Form1 is called frmForm1 - is not a subform?
form2 is called frmForm2 with the public sub TestCall - is not a subform?

If all you're doing is trying to run a function in a form from another form then here:
Code:
Call Forms!frmForm2.TestCall
And to answer your question, no you don't need to reference the tab control.
 
The error message indicates that the form you're calling the function from is not a subform. So let's get some clarity on a few things.

Tabbed form is called frmTab - is a tab control and not a form?
Form1 is called frmForm1 - is not a subform?
form2 is called frmForm2 with the public sub TestCall - is not a subform?

If all you're doing is trying to run a function in a form from another form then here:
Code:
Call Forms!frmForm2.TestCall
And to answer your question, no you don't need to reference the tab control.

frmTab is the Form that has a Tab on it,
on one of the Tabs there are 2 Subforms called:

Form1
Form2

Form 1 has a Button on it, that i want to access a Sub on Form 2 with to do further actions.

(the names are actually different, i am just simplyfying the names to make it easier.
 
Let's have a look at your db. I will be able to tell you what's going on.
 
Here are the forms im working with.

Thank you for the help in advance
 

Attachments

Either one of:
Code:
    Call Forms("frmCustomerCenter").[COLOR=Red]subf[/COLOR]CustomerCenterView.Form.TestCall

    Call Forms("frmCustomerCenter").Controls("[COLOR=Red]subf[/COLOR]CustomerCenterView").Form.TestCall
By the way I renamed the name of the subform control to subfCustomerCenterView. See attached.
 

Attachments

Thank you very much,

Is that the usual practice subf?

Your a life saver!
 

Users who are viewing this thread

Back
Top Bottom