Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Call function/sub in parent form?

Posted on 2002-04-26
4
Medium Priority
?
655 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 200 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

670 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