0

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.

Rab

3
Contributors
6
Replies
18
Views
4 Years
Discussion Span
Last Post by Begginnerdev
0

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 by tinstaafl

0

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
        Get
            return sFilter
        End Get
        Set(value As String)
            sFilter=value
            PopulateFields()
        End Set
    End Property

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

End Class
0

Something like:

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

da.Fill(ds,"MyTable")

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")
        'ect....
    Next
End If
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.