I have a form with nothing but a combobox and go button. The combobox is populated by the "Name" field in the table. What I want to do, is populate text fields on a new form with the rest of the information in the table, based on what selected in the combobox when "Go" is clicked.


If your other form is called Form2 then declare a new form of type Form2,Dim NewForm As New Form2,now you have full access to any of the controls in Form2, NewForm.TextBox1.Text = "some string". When that is all done just call the Show method, unless you need a DialogResult returned, or you want NewForm to block the calling form until NewForm is closed, then use the ShowDialog method.

Edited 3 Years Ago by tinstaafl

What are you storing these values in, a database?

If so, just write a sub routine that retreives information based on your selected:

Public Class Form1
    Private Sub GO_Click(ByVal sender As Object, ByVal e As EventArgs) Handles GO.Click
        Form2.Filter = ComboBox1.Text
    End Sub
End Class

Code for second form:

Public Class Form2
    Private sFilter As String = String.Empty

    Public Property Filter As String
            return sFilter
        End Get
        Set(value As String)
        End Set
    End Property

    Private Sub PopulateFields()
            'Place query code here.
        Catch ex As Exception
        End Try
    End Sub

End Class

Something like:

Dim myCon As New OleDBConnection("ConnectionStringHere")
Dim da As New OleDBDataAdapter(New OleDBCommand("SELECT * FROM " & Filter,myCon))
Dim ds As New DataSet


If Not IsNothing(ds.Tables("MyTable")) And ds.Tables("MyTable").Rows.Count > 0 Then
    For Each r As DataRow in ds.Tables("MyTable").Rows
        TextBox1.Text = r("MyField1")
        TextBox2.Text = r("MyField2")
End If

Thats pretty much what I tried, got an error about two bindings. Hmmm

This article has been dead for over six months. Start a new discussion instead.