Solved

Call function/sub in parent form?

Posted on 2002-04-26
4
653 Views
Last Modified: 2012-06-27
I have form frmParent that calls form frmChild via:
frmChild.Show vbModal, Me

If I have a function/sub in frmParent's code, how can I call that from frmChild's code? An important thing to note is that the function/sub needs to modify controls on frmParent.
0
Comment
Question by:dplambert
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 18

Accepted Solution

by:
mdougan earned 50 total points
ID: 6972206
You can do this if the Function/Sub in the frmParent is declared as Public.

The syntax in the frmChild's code would be:

frmParent.runSomeParentCode()

And the parent code can do whatever it wants to with it's controls
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6972367
If you will call function from different parts of your program, i recomend you that use a module and write those public functions there.
0
 
LVL 18

Expert Comment

by:mdougan
ID: 6972622
Richie, I used to think the same thing, but then it occured to me that a form is a lot like a Class, just with a GUI part.  I started encapsulating program functionality by Form and by Class, and stopped using modules for just about everything.  I even include methods in the form that are used to Show the form, and rarely issue a frmChild.Show... instead, I might have a Function in frmChild that is called:

Public Function AddContact(lDeptID) as boolean
   Load frmChild ' probably not necessary
   txtDeptID.Text = lDeptID
   frmChild.Show vbModal
' Now, user has clicked OK which issues a me.hide
   InsertContactToDB
   AddContact = True
End Function

Then, in frmParent, you can call to Add the contact just by issuing a method call:

if frmChild.AddContact(CLng(txtDeptID.Text)) Then
   RefreshContacts()
End if

And that sort of encapsulates all the GUI and other functionality associated with adding a contact.  Plus, I can now copy that frmChild to another project and not have to worry about dependencies with other modules....
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6972672
OK. i only do that way when create Active x controls.
Cheers
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question