How to communicate between forms

Posted on 2002-03-30
Last Modified: 2010-05-02
How do you communicate between forms in VB.NET? In VB 6 I am used to typing for example How is this accomplished in VB.NET?
Question by:pcaviness
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
LVL 28

Expert Comment

ID: 6907948
You should create instances of the forms using variables, since they are, after all, just classes that should be instantiated that way anyways, e.g.,

Dim f As frmMySecondForm = New frmMySecondForm()

Author Comment

ID: 6908166
I know about creating new instances of the forms but I want to be able to change elements on existing forms from other forms. Any suggestions?

Accepted Solution

carloss earned 75 total points
ID: 6908395
Because as AzraSound mentioned above, a form is just another object.  You can create public methods on the form that can be called from other sections in your code as you would any other method of an object.  Such as


Public Sub LockTextBox()

TextBox1.Locked = True

End Sub

Any other place in code:


You can also define a public object and set its instance equal to the element you want such as:


Public MyTextBox as TextBox

Public Sub Form1_OnLoad()

Set MyTextBox = TextBox1

End Sub

Any other place in code:

Form1.MyTextBox.Text = "Set from somewhere else"

Author Comment

ID: 6909229
I had to figure out a few things to get it to work such as making the objects shared. But it worked. Thanks

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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
Course of the Month7 days, 3 hours left to enroll

623 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