PC Review


Reply
Thread Tools Rate Thread

Accessing another form's fields

 
 
John
Guest
Posts: n/a
 
      29th Dec 2008
Hi

From FormA I am opening another form FormB using ShowDialog(). Is there a
way to access a text field on FormA (calling form) from FormB (called form)?

Thanks

Regards


 
Reply With Quote
 
 
 
 
Armin Zingler
Guest
Posts: n/a
 
      29th Dec 2008
John wrote:
> Hi
>
> From FormA I am opening another form FormB using ShowDialog(). Is
> there a way to access a text field on FormA (calling form) from FormB
> (called form)?


My default answer: If you want to access an object you need a reference. If
you don't have it make it available. How, depends on when you want to access
FormA and which information do you really need. IMO, from an OO point of
view, I favor writing as abstract code as possible, so I think passing a
Form reference is not necessary. In short, what's your goal?


Armin

 
Reply With Quote
 
rowe_newsgroups
Guest
Posts: n/a
 
      29th Dec 2008
On Dec 29, 6:40*am, "John" <i...@nospam.infovis.co.uk> wrote:
> Hi
>
> From FormA I am opening another form FormB using ShowDialog(). Is there a
> way to access a text field on FormA (calling form) from FormB (called form)?
>
> Thanks
>
> Regards


Simplest way I can think is to use the overload on ShowDialog() and
pass in the calling form as the owner. Then, from the called form, you
can access any public member on the calling form like so:

///////////
Dim owner = TryCast(Owner, Form1)

If owner IsNot Nothing Then
'// Do something cool with the form
End If
///////////

However, I would prefer that you do something along the lines of
constructor injection, feeding whatever the called form needs into the
constructor, and preventing the need for the above backreferencing
(not to mention it decouples the called form from the calling form).

Thanks,

Seth Rowe [MVP]
http://sethrowe.blogspot.com/
 
Reply With Quote
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      29th Dec 2008
John,

For a ShowDialog form I mostly use simple "friend" fields in the showdialog
form, that gives me the most flexibility.

For those who want to tell this is not correct, you are right, byt I do this
only by one time to use ShowDialog forms.

Cor

"John" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi
>
> From FormA I am opening another form FormB using ShowDialog(). Is there a
> way to access a text field on FormA (calling form) from FormB (called
> form)?
>
> Thanks
>
> Regards
>


 
Reply With Quote
 
John
Guest
Posts: n/a
 
      30th Dec 2008
I need to copy info from two text boxes to the called form.

Regards

"Armin Zingler" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> John wrote:
>> Hi
>>
>> From FormA I am opening another form FormB using ShowDialog(). Is
>> there a way to access a text field on FormA (calling form) from FormB
>> (called form)?

>
> My default answer: If you want to access an object you need a reference.
> If you don't have it make it available. How, depends on when you want to
> access FormA and which information do you really need. IMO, from an OO
> point of view, I favor writing as abstract code as possible, so I think
> passing a Form reference is not necessary. In short, what's your goal?
>
>
> Armin



 
Reply With Quote
 
John
Guest
Posts: n/a
 
      30th Dec 2008
Hi Cor

Could you kindly give a simple example of this?

Thanks

Regards

"Cor Ligthert[MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> John,
>
> For a ShowDialog form I mostly use simple "friend" fields in the
> showdialog form, that gives me the most flexibility.
>
> For those who want to tell this is not correct, you are right, byt I do
> this only by one time to use ShowDialog forms.
>
> Cor
>
> "John" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Hi
>>
>> From FormA I am opening another form FormB using ShowDialog(). Is there a
>> way to access a text field on FormA (calling form) from FormB (called
>> form)?
>>
>> Thanks
>>
>> Regards
>>

>



 
Reply With Quote
 
Jack Jackson
Guest
Posts: n/a
 
      30th Dec 2008
I would do this one of two ways:

1. Make another constructor for FormB that takes two string values:

Public Sub New(val1 As String, val2 As String)

2. Add a method to FormB that takes the two string values as
parameters and call it after you instantiate FormB but before you call
ShowDialog.

On Tue, 30 Dec 2008 02:01:13 -0000, "John" <(E-Mail Removed)>
wrote:

>I need to copy info from two text boxes to the called form.
>
>Regards
>
>"Armin Zingler" <(E-Mail Removed)> wrote in message
>news:%(E-Mail Removed)...
>> John wrote:
>>> Hi
>>>
>>> From FormA I am opening another form FormB using ShowDialog(). Is
>>> there a way to access a text field on FormA (calling form) from FormB
>>> (called form)?

>>
>> My default answer: If you want to access an object you need a reference.
>> If you don't have it make it available. How, depends on when you want to
>> access FormA and which information do you really need. IMO, from an OO
>> point of view, I favor writing as abstract code as possible, so I think
>> passing a Form reference is not necessary. In short, what's your goal?
>>
>>
>> Armin

>

 
Reply With Quote
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      30th Dec 2008
Something like this

\\\
Class ShowDialogFormA
....
friend A as string
.....
End Class

Class MainForm
....
private sub loadform
dim A as new ShowDialogFormA
A.A = "this I want to show"
A.ShowDialog
dim B as string
B = A.A
A.Dispose
...
end sub
....
end Class
///

Cor

"John" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Cor
>
> Could you kindly give a simple example of this?
>
> Thanks
>
> Regards
>
> "Cor Ligthert[MVP]" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> John,
>>
>> For a ShowDialog form I mostly use simple "friend" fields in the
>> showdialog form, that gives me the most flexibility.
>>
>> For those who want to tell this is not correct, you are right, byt I do
>> this only by one time to use ShowDialog forms.
>>
>> Cor
>>
>> "John" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> Hi
>>>
>>> From FormA I am opening another form FormB using ShowDialog(). Is there
>>> a way to access a text field on FormA (calling form) from FormB (called
>>> form)?
>>>
>>> Thanks
>>>
>>> Regards
>>>

>>

>
>


 
Reply With Quote
 
Armin Zingler
Guest
Posts: n/a
 
      30th Dec 2008
John wrote:
> I need to copy info from two text boxes to the called form.


I also asked "when" because it might be not when calling/showing FormB.


Armin

 
Reply With Quote
 
Backwater Geezer
Guest
Posts: n/a
 
      30th Dec 2008
What about making that reference a property?
Why everyone wants to complicate everything!

MH
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing another form's fields John Microsoft VB .NET 10 30th Dec 2008 05:53 PM
Accessing fields from form andrew3254 Microsoft Access Form Coding 2 24th Mar 2008 04:14 PM
Accessing input fields declared outside the form Jessica Weiner Microsoft ASP .NET 2 5th Jul 2006 06:35 AM
Accessing calculated fields for a certain record on a form David Walker Microsoft Access 1 15th Apr 2004 07:10 PM
Accessing table and/or form fields from VBA Steve Marsden Microsoft Access VBA Modules 1 10th Jul 2003 12:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:13 PM.