Results 1 to 4 of 4

Thread: Combo

  1. #1
    Join Date
    Sep 2003
    Location
    Raleigh, NC
    Posts
    183

    Unanswered: Combo

    I have two combo box named "cboMPTID" and IPTID" This is what i'm trying to do.

    Each time user Picks MotherID from "cboMPTID" they should only see releted records in "CboIPTID"

    For example: Mother ID = 100 which has Infant ID = 100-01 and 100-02 so when user pick value 100 from cboMPTID the cboIPTID should only display 100-01 and 100-02. I have wrote this code but i get error massage.

    Private Sub cboMPTID_Click()

    Dim CON As ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim sql As String

    Set CON = CurrentProject.Connection
    sql = "Select MPTID from tblMother where MotherID = " & cboMPTID.Value
    rs.Open sql, CON

    Dim i As Integer
    For i = 0 To cboIPTID.ListCount - 1
    cboMPTID.RemoveItem (0)
    Next i
    Do While Not rs.EOF
    cboMPTID.AddItem rs(0)
    rs.MoveNext
    Loop



    End Sub
    Skharva

  2. #2
    Join Date
    Dec 2003
    Posts
    268

    Change the recordsource of the Combobox

    You can have the values for the combo box cboIPTID tied to the selected value of cboMPTID.

    for the control source of IPTID
    "SELECT InfantID FROM tblInfant WHERE MotherID = " & cboMPTID.Value

    Then on the click event for the MotherID Combobox just have it requery the Infant pull down list.

    This might be a little easier than the other method you were attempting.

  3. #3
    Join Date
    Sep 2001
    Location
    Chicago, Illinois, USA
    Posts
    601
    There is no need for code here.

    The entire thing can be done with SQL in the RowSource of the comboboxes.

    The RowSource of the second combobox will simply have a criteria pointing to the first combobox.

    You must, however, remember to requery the second combobox on the AfterUpdate of the first combobox.

  4. #4
    Join Date
    Sep 2003
    Location
    Raleigh, NC
    Posts
    183
    Originally posted by PracticalProgram
    There is no need for code here.

    The entire thing can be done with SQL in the RowSource of the comboboxes.

    The RowSource of the second combobox will simply have a criteria pointing to the first combobox.

    You must, however, remember to requery the second combobox on the AfterUpdate of the first combobox.
    Ok i did this using RowSource

    How can i display more fields on form based on selected value frm cboIPTID ? Below is the code i use but it gives me error "TYPE MISMATCH"

    Private Sub cboIPTID_AfterUpdate()
    ' Find the record that matches the control.
    Dim rs As Object

    Set rs = Me.Recordset.Clone
    rs.FindFirst "[InfantID] = " & Str(Me![cboIPTID])
    Me.Bookmark = rs.Bookmark
    End Sub

    Private Sub cboMPTID_AfterUpdate()
    ' Find the record that matches the control.
    Dim rs As Object

    Set rs = Me.Recordset.Clone
    rs.FindFirst "[MotherID] = " & Str(Me![cboMPTID])
    Me.Bookmark = rs.Bookmark

    End Sub
    Skharva

Posting Permissions

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