473,387 Members | 1,590 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

how to call subs on another form in the same tab control?

I have a form 'frmHome'. It has a tab control 'tabCtrl'. The tab control has two forms: 'frmContacts' and 'frmProjects'.

On the contacts form I can see the projects a person is involved with. On the Projects form I can see the people associated with a project.

I want to dbl-click on a project from the contacts form, and have it take me to that project on the projects form. I want to similarly click a person on the projects form, and have it take me to that person on the contacts form.

So far, I can dbl-click on a project in the contacts form, and the code will change the tab control to the appropriate page with the projects form. Also, there is a public sub on the projects page which will set the current record to the value of a global variable. I tested that sub with a command button and it works great.

BUT - I can't figure out how to call that public sub from the other form. I can't figure out the proper syntax to reference it.

Help? Thanks.
Jan 30 '12 #1

✓ answered by Stewart Ross

From VBA code you can refer to a public sub or function in another open form (frmProjects in this case)as follows:

Expand|Select|Wrap|Line Numbers
  1. Form_frmProjects.YourSubName

More generally, to assign the value of a function on another form to a variable, and to call a sub:

Expand|Select|Wrap|Line Numbers
  1. SomeVar = Form_YourFormName.YourFunctionName([Arg1], [Arg2], ..., [ArgN])
  2. Form_YourFormName.YourSubName [Arg1], [Arg2], ..., [ArgN]
This will only work for public subs or functions; those declared as private are not accessible outside the scope of their own form. After you type the dot separator Intellisense will show you the properties and methods available to you. Your public sub or function should show on the Intellisense list if all is well.

-Stewart

12 2963
Mihail
759 512MB
You lost me .
Jan 30 '12 #2
NeoPa
32,556 Expert Mod 16PB
You should find enough reference material in Referring to Items on a Sub-Form to help with this. If not then try to explain what you need further in clear terms.
Jan 30 '12 #3
Stewart Ross
2,545 Expert Mod 2GB
From VBA code you can refer to a public sub or function in another open form (frmProjects in this case)as follows:

Expand|Select|Wrap|Line Numbers
  1. Form_frmProjects.YourSubName

More generally, to assign the value of a function on another form to a variable, and to call a sub:

Expand|Select|Wrap|Line Numbers
  1. SomeVar = Form_YourFormName.YourFunctionName([Arg1], [Arg2], ..., [ArgN])
  2. Form_YourFormName.YourSubName [Arg1], [Arg2], ..., [ArgN]
This will only work for public subs or functions; those declared as private are not accessible outside the scope of their own form. After you type the dot separator Intellisense will show you the properties and methods available to you. Your public sub or function should show on the Intellisense list if all is well.

-Stewart
Jan 30 '12 #4
NeoPa
32,556 Expert Mod 16PB
While all that Stewart says is correct, if you want to refer to items within a closed list such as this, and I'm assuming you want to refer to frmProjects from withing frmContacts, you have another option, which is to refer to it relationally.

I don't actually know the names of your subform controls on your main form, but if they were called sfmContacts and sfmProjects then referring to a procedure MyProcedure found in frmProjects from code in frmContacts could be handled by saying :
Expand|Select|Wrap|Line Numbers
  1. Me.Parent.sfmProjects.Form.MyProcedure
or even :
Expand|Select|Wrap|Line Numbers
  1. Me.Parent.sfmProjects!MyProcedure
Jan 30 '12 #5
Thanks, everyone. Stewart's answer did the trick: Form_frmProjects.PublicSubName

NeoPa, I couldn't get your syntax to work - that's similar to the other things I tried before coming here (which also didn't work). I've done that sort of thing many times before, but never when the forms are on a tab control. I think the tab control confuses the syntax somehow. In the past I've emulated a tab control just by having buttons on the forms - and that seemed easier in many ways than the tab control is turning out to be.

At any rate, thanks for the help.
Jan 31 '12 #6
NeoPa
32,556 Expert Mod 16PB
Tab controls don't actually effect the referencing at all. They confuse mostly by people thinking they need to include it as some part of the reference.

Anyway, I'm sure you're happy with Stewart's solution - and it's something that's very useful to understand anyway (The full name of the object modules themselves).
Jan 31 '12 #7
So, from a syntax standpoint, I should just consider the two tabbed forms as if they were subforms on the main form?

Expand|Select|Wrap|Line Numbers
  1. Instead of this:
  2. Main form
  3.   |-- tab ctrl
  4.         |--- form1
  5.         |--- form2
  6.  
  7.  
  8. I should think this?
  9. Main form
  10.   |--- subform1
  11.   |--- subform2
Jan 31 '12 #8
Stewart Ross
2,545 Expert Mod 2GB
Forms on a tab control are subforms of the main form itself - the tab control does not affect their referencing at all, as NeoPa said. This is as you have noted in the second part of your post above.

-Stewart
Jan 31 '12 #9
Thank you both. That clarifies a lot.

One more question: When the main form is open, are the subforms (the forms on the tab control) also considered 'open'?

One of the options I tried early on gave me an error saying that I couldn't reference controls on the projects form unless it was open.
Jan 31 '12 #10
Stewart Ross
2,545 Expert Mod 2GB
The subforms are indeed open - but they are not open in the same way they would be if they were opened on their own outside of the main form.

When you open a main form, the subforms are forms embedded as controls within the main form itself. If you were to check that, say, your form called frmProjects is loaded you will find that it is not. If you attempt to access its controls as if it is a run-time error will occur.

To access the controls within one of your subforms when the main form is open you have to refer to the subform control's form property, as detailed in the article hyperlinked by NeoPa in post #3. There are many (equivalent) ways to do so, so this example is only one of the possibilities:

Expand|Select|Wrap|Line Numbers
  1. Forms("frmHome")!frmProjects![Your control name]
-Stewart
Jan 31 '12 #11
Now I get it! NeoPa's linked article confused me before because I wasn't thinking of the forms on the tab control as subforms. Now that I re-read the article it makes a lot more sense.

Thanks again.
Jan 31 '12 #12
NeoPa
32,556 Expert Mod 16PB
Everything Stewart said :-)

I'm pleased to hear things make more sense now. I never felt it was necessary before, as logically they have so little effect, but I may revisit the article and explain explicitly that tab controls don't effect the referencing of items 'contained' within them at all.

PS. I've updated it now. I must admit though, I found the explanation of how sub-forms are handled (within Subform controls) already clearly stated in the introduction. No updates were required for that part at least.
Jan 31 '12 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: simonmarkjones | last post by:
Hi, I'm having a bit of trouble editing an old database that was created quite a while ago by someone else. There is a form that lets the user select a member of staff and show details about the...
7
by: Dave | last post by:
I have two forms, Form1 and Form2. From Form2, how do I reference the value in a control on Form1? Or perhaps a more specific question: Form1 contains a textbox with the value of 10. This form...
4
by: Sandy MacDonald | last post by:
Hi everyone, This is a very simple question, but I am new to VB.net and can't seem to get a simple call to another form to work. example: If (scenerio is true) then load frmLogin end if ...
0
by: Geraldine Hobley | last post by:
Hello I have a problem whereby I have a treeview control on one form called projecttree and I wish to clea the nodes from this control in another form The form that contains the treeview is...
5
by: Mrozu | last post by:
Hi I have frm1. On this form button.Click code for this button is: Dim frm2 as New frm2 frm2.show So after click, frm2 form is shown.
2
by: planetthoughtful | last post by:
Hi All, I have a calendar form that updates a date field on the form from which it was called. I have code in the OnChange event of the date field that I would like performed whenever the date...
4
by: Gerhard | last post by:
I have an MS Access app with multiple forms. One of the forms has a Toolbar (MsComctlLib.Toolbar) and it works as advertised. I handle the buttons in the Toolbar1_ButtonClick event. I would like...
6
by: Franck | last post by:
I know in vb6 it was super easy to pass parameter or either read example the textbox1.text on the already open form form2 like all object were as public. but is there a way to do something that...
1
by: Martin Bentler | last post by:
Right now, I have a form, locked records, on which I have a CommandButton that opens a second form (much like the first) but open for editing, plus allowing the user to manipulate other areas of the...
4
by: JeremyI | last post by:
The form I am working on at the moment is designed to allow a data entry person to add new questions for the assessment of some properties. I am trying to set up cascading combo boxes that force the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.