Passing a variable value between two forms

jeva39

Well-known member
Joined
Jan 28, 2005
Messages
135
Location
Panama
Programming Experience
1-3
I need to pass the value of a public variable (vNivel) from a Form to another in the same application. I try many ways but always the result is bad. Please, how I can do this?

Thanks...
 
If one form is opening the other, pass the variable in the constructor. Otherwise, you must put the variable in a place visible to both forms, like as a public variable/property of a module. There are many other posts on these forums relating to communication between forms that answer the same or similar questions.
 
Public Variables Module

Add a Module to your project called 'PublicVariables'. Add statements like these to the module.

Public iCurrentPartid As Integer
Public tCurrentPartName As String

the module makes the variables 'iCurrentPartId' & 'tCurrentPartName' available to all forms in the project.

On FORM1 set the variables to something:
iCurrentPartid = Grid.Columns("part id").Value
or
tCurrentPartName = TextBox2.text

call FORM2


then on form2 you can set anything to the public variable, such as an SQL Parameter.

SqlSelectCommand1.Parameters("@partid").Value = iCurrentPartid
or
textbox1.text = tCurrentPartName

hope this helps
 
Last edited:
Back
Top