Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2011

    Unanswered: Multiple ComboBox Help!

    I have started a form application using visual studio 2010 express, vb programming. I'm using Access as my database.

    My goal is to have ComboBox1 display a ProjectID and ComboBox2 display a TestNumber. Once the Test Number is selected I want my textboxes in the form to display fields from the row that the selected Test Number is in.

    I have 2 tables set up right now "Projects" and "TestData". The "Projects" table has a [ProjectID] field, the remaining fields are just misc. project data. The "TestData" table also has the [ProjectID] field, and then the [TestNumber] field, then the remaining fields are misc. data.

    Filling [ProjectID] in textbox1 is easy, in the properties I select DataSource from the Projects table, display [ProjectID] field. Where I'm having troubles is ComboBox2 displaying the TestNumber. If I select that field, it fills the ComboBox with EVERY TestNumber there is. So for Project 1 there is a test 1... over 500 projects, that combobox lists 500 Test 1's, no way to tell what project it belongs to...

    How do I make ComboBox2 only display Test Numbers that pertain to the Project number selected in ComboBox1?

    Using this code I can get it to work:

    Dim ProjectNo, SQLString As String
    Dim dtTableData As New DataTable()
    Dim dbDataAdapter As OleDbDataAdapter
    Dim ConnectionString As String = ("Provider = Microsoft.Jet.OLEDB.4.0;" & "Data Source = Database.MDB")
    ProjectNo = ComboBox1.Text
    SQLString = ("Select * FROM TestData WHERE ProjectID = " & "'" & ProjectNo & "'" & "")
    dbDataAdapter = New OleDbDataAdapter(SQLString, ConnectionString)
    ComboBox2.DataSource = dtTableData

    I also imported

    Problem with this code is it will only filter data in ComboBox 2 but when you make your selection from ComboBox2 it won't activate the row so none of my textboxes fill. Before the code/query is ran it fills up the textboxes perfectly after every selection I just have no idea what project that report number belongs to. I can load the form with ComboBoxes and they display the corresponding row data because I use a "datasource" instead of textbox "databindings" but I don't want to use 20 comboboxes as my entry form...

    Any help would be greatly appreciated as this has drove me nuts spending hours searching threads and youtube!

  2. #2
    Join Date
    Aug 2004
    Dallas, Texas
    Do you have a method to deal with cboTest changes? The selected cbo changed event should handle this with a call to the db and return the specific results. So you should have a sub to handle the request and populated the test boxes. Yes?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts