Paul Williams
Paul Williams

Reputation: 1598

Passing a variable to another form, from another when invoked by an action

I might be making this more complicated than I have to.

I have a form in Visual Basic that is adding a row of data to an Access Database.

What will happen (or rather what I would like to happen) is that when the form is created, a row will be added to said database. Once that row is added, I want to have another form open (called NewWindowA) which will pull information on that database that is related to the ID of the row that was created from the first form.

I know that in NewWindowA I need to have the form load the values on Load. But my question is: How do you pass a value to a new window that's invoked by some action?

Upvotes: 3

Views: 12689

Answers (2)

Amir Magdy
Amir Magdy

Reputation: 187

just create a public sub in the new form possibly called (prepareUI) that new sub has the parameter you want to pass as its parameters access the controls and fill them .

in the original form instantiate the new form and call the show method and then call the sub prepareUI sending the paremateres you need

Upvotes: 4

Amen Ayach
Amen Ayach

Reputation: 4348

You can make a constructor of newwindowa that takes the id Like :

Public Sub New(ByVal ID as Integer) 
   'Do stuff
End Sub

Another Choice you have that you make a global property in newwindowa

Private _ID As Integer
Public Property ID() As Integer
    Get 
        Return _ID
    End Get
    Set(ByVal value As Integer)
        _ID = value
    End Set
End Property

When you want to call neweindowa:

Dim n as New NewWindowA
n.ID = 12312
n.Show()

Upvotes: 6

Related Questions