473,657 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pass a value from a child form to a Parent

Rob
I have a control (Button) on a Parent form which opens a Windows form... all
I want to do is pass a value from the child form back to the parent... it
should be so simple... i.e.
ParentFormName. Textbox1.text=C hildFormName.Te xtBoxWhatEver.T ext... but
nothing like this works.

Any ideas ?
Jun 27 '08 #1
5 4224
"Rob" <ro***@yahoo.co mschrieb
I have a control (Button) on a Parent form which opens a Windows
form... all I want to do is pass a value from the child form back to
the parent... it should be so simple... i.e.
ParentFormName. Textbox1.text=C hildFormName.Te xtBoxWhatEver.T ext...
but nothing like this works.

Any ideas ?
General answer: To access an object, you need a reference.

The specific answer depends on many things. First, is the 2nd Form shown
modally (Showdialog)? When do you want to access the other form? Which
event? Writing abstract and reusable code, it's usually not common
practice to access the caller from the callee.
Armin

Jun 27 '08 #2
Rob,

As it is a dialogform, than it is as simple to create a friend property in
your dialog and get that when the dialog is done.

Cor

"Rob" <ro***@yahoo.co mschreef in bericht
news:id******** *************** *******@comcast .com...
>I have a control (Button) on a Parent form which opens a Windows form...
all I want to do is pass a value from the child form back to the parent...
it should be so simple... i.e.
ParentFormName .Textbox1.text= ChildFormName.T extBoxWhatEver. Text... but
nothing like this works.

Any ideas ?


Jun 27 '08 #3
On May 27, 1:34 am, "Rob" <ro...@yahoo.co mwrote:
I have a control (Button) on a Parent form which opens a Windows form... all
I want to do is pass a value from the child form back to the parent... it
should be so simple... i.e.
ParentFormName. Textbox1.text=C hildFormName.Te xtBoxWhatEver.T ext... but
nothing like this works.

Any ideas ?
My personal method is to have an event on the child form that will
return the value. Then when the child form is created, the parent form
(or any other form that cares about that event) should subscribe to
that event. Then whenever the value is created / changed on the child
form the other forms will be able to act accordingly. This method also
promotes loosely couple forms, which could save some major headaches
in maintenance or reuse.

Thanks,

Seth Rowe [MVP]
Jun 27 '08 #4

A few thoughts:

Form is a class like any other class. You pass values through
properties like you would any other class.

I recommend that you separate your values from the user
interface instead of trying to access them from the controls.

In other words: When the childform class is asked to close,
clientform should grab the values from its controls and store
them in private members, accessible through properties.

One childform has closed, parentform can access the values
through those properties.

For a simple scenario like this, I would suggest that this is the
way to go.

For more complex scenarios where multiple objects need to
react to changes in one or more values, the idea of subscribing
to events has some validity (but do keep track of what object
initiated a change and what objects should just reflect the change).

VB2005 and later supports the VB6 concept of a shared default
instance of a form. I have my reservations about this. I like to
know/control whether a form is freshly initialized or reused.

When/if using ShowDialog to display the form, remember to use
..DialogResult = ... to close it instead of Me.Close.

Regards,

Joergen Bech

On Tue, 27 May 2008 01:34:39 -0400, "Rob" <ro***@yahoo.co mwrote:
>I have a control (Button) on a Parent form which opens a Windows form... all
I want to do is pass a value from the child form back to the parent... it
should be so simple... i.e.
ParentFormName .Textbox1.text= ChildFormName.T extBoxWhatEver. Text... but
nothing like this works.

Any ideas ?
Jun 27 '08 #5
On May 27, 7:31 pm, "Rob" <ro...@yahoo.co mwrote:
Hi

Regarding... 1) best OO choice - create a message and have the parent
subscribe to
it.

Do you have some sample code that demonstrates this ?
Rather than rewrite someone else's work this article describes it
fairly well.
http://forums.microsoft.com/MSDN/Sho...46657&SiteID=1
Jun 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2833
by: Filiz Duman | last post by:
Hi, I am opening a pop up window (child) from a parent window. The Child window does show a table with multiple columns and rows, each showing a value, e.g. 9 or 10 or etc. I have the values as hyperlinks, so that if a number is selected in the child window it should close automatically and insert the selected value in a text field in the parent window. I have created following code, but does not work. Any ideas why or other...
3
3883
by: Lyn | last post by:
Hi, I have been experiencing a problem passing a LIKE statement in the WHERE argument of a DoCmd.Openform statement. I have posted that issue separately. However, in an attempt to work around the problem, I thought of using OPENARGS to pass information to the form being opened (instead of using WHERE). In the parent form, I have generated a RecordSet (RS) with the information
2
6965
by: Chandru | last post by:
hi I want to know how to pass values from different forms. That is, i created one parent form. from there i opened child form modeless way. Once i close the child form i need some value from child form that to be transferred in Parent form. thanks in advance.
3
2589
by: Chris | last post by:
Before I started to create table, etc to track unique form field record number assigments I thought I'd check to see if there is now a better way to do this in .NET. I have a parent form (table) and children form (table). Relationship equals one to many. I'd like to auto number the fields accordingly and traditionaly I assign a unique number based on a table value that I retrieve + 1. i.e. Parent record field value = 1 Children record...
3
1726
by: Vivek | last post by:
Hi, I wish to refresh the parent form and pass the new values from child form. How can I do it? Thanks
2
2325
by: Karl Rhodes | last post by:
I have an application which uses mutliple forms for different tasks, all of which are mdi child forms to the applications MDI Parent form. One of these child forms (form1) will be used to select a record from somewhere within a hierarchy (using a treeview and listbox to narrow down the search) and then the details from this record should be displayed on an entirely different child form (form2) by the click of a button. What I want to...
3
3352
by: juliusy | last post by:
I have Form1 launches Form2. On Form2, user will enter input (a string). When I click OK to close Form2, I need to have that string value populated TextBox1 on Form1 (the parent form). I only find clues on doing the other way (passing from parent to child), which I have already been doing fine. But don't know how to let child form recognize (already opend/launched) parent form to access control there. Thank you!
12
11073
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms. Here is a newbie mistake that I found myself doing (as a newbie), and that even a master programmer, the guru of this forum, Jon Skeet, missed! (He knows this I'm sure, but just didn't think this was my problem; LOL, I am needling him) If...
0
8399
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8504
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8606
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6169
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4159
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2732
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1622
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.