We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,987 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

What Form Called a Form - Part 2

I failed to ask my entire question on part 1. Although codeorder gave me the answer
I needed I have one more part which I will put in bold.

I have 3 forms: Form1, Form2 and Form99. Form1 and Form2 both call Form99.
What statement(s) does Form99 use to determine which form called it (Form1 or Form2).

Form1
   Form99.Show

Form2   
   Form99.Show

Form99

   Which form called me?

Thank You.

Form1 and Form2 have several textboxes - Let's just say TextBox1 and TextBox2.
By using the field sNameOfForm that codeorder said to use I want to use sNameOfForm
to access TextBox1 and Textbox2 .text property using sNameOfForm for the Form Name.

Instead of coding in Form99: MsgBox(Form1.TextBox1.Text)
MsgBox(sNameOfForm.TextBox1.text)

In other words I want to use the Form Name (sNameOfForm) that was supplied to Form99 and
access the textboxes on either Form1 or Form2 without hardcoding the form name.

Thank you.
tfj

3
Contributors
3
Replies
11 Hours
Discussion Span
1 Year Ago
Last Updated
4
Views
Question
Answered
tfj
Newbie Poster
9 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

You could use form's owner property.

Calling Form99 would be

Form1
Form99.Show(Me) ' Me i.e. owner is now Form1

Form2
Form99.Show(Me) ' Me i.e. owner is now Form2

To find out who's the caller (i.e. owner), read the owner property:

Private Sub Form99_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

      ' Set form's caption to show the owner
      ' Here the 'Me' refers to Form99
      Me.Text = Me.Owner.Text & " is the owner (caller) of the Form99"

End Sub

HTH

Teme64
Veteran Poster
1,040 posts since Aug 2008
Reputation Points: 218
Solved Threads: 206
Skill Endorsements: 5

See if this helps.
Form99:

Public Class Form99
    Public selForm As Form = Nothing

    Private Sub frm99_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.TextBox1.Text = CType(selForm.Controls("TextBox1"), TextBox).Text
        Me.TextBox2.Text = CType(selForm.Controls("TextBox2"), TextBox).Text
    End Sub
End Class

All other Forms:

With Form99
            .selForm = Me
            .Show()
        End With
codeorder
Postaholic
2,124 posts since Aug 2010
Reputation Points: 256
Solved Threads: 387
Skill Endorsements: 8

Thank you codeorder and Teme64. Both answers did the trick!

tfj
Newbie Poster
9 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 1 Year Ago by Teme64 and codeorder

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0791 seconds using 2.68MB