Solved

Call function/sub in parent form?

Posted on 2002-04-26
4
650 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
  • 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel - Save a copy of work book 13 85
Spell Check in VB6 13 113
Added a column screws up code 5 57
Export Data to Different .csv Files 26 105
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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

777 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