Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2003
    Posts
    22

    Red face Unanswered: 3 combo boxes........

    I have two combo boxes working fine, when you select a value from the first combo box it narrows down the selection in the second box. Now I need it to be able to narrow down a selection in the third combo box depending on the selection of the second combo box. I can't seem to get it right.

    Here is the details:

    first combo box - cboDepartmentID takes values from tblDepartment field name - Department

    2nd - cboDivisions takes values from tblDivisions, field name - Divisions

    3rd - cboSections takes values from tblSection, field name - Sections


    After update code of first combo box:

    --------------------------

    'declaration of variable
    'included DAO 3.6 library
    Dim SQLSTmt As String
    Dim curdb As Database
    Dim adrs As DAO.Recordset
    Dim deptID As Integer 'holds the Department ID number

    'portion added by vbaProgrammer
    Set curdb = CurrentDb()
    'Handling absense of value
    If Me![cboDepartmentID].Value = "" Then
    MsgBox " please select the value and try again", vbCritical, "Updating Combobox"
    Exit Sub
    End If
    'Handling the data in both combo boxes
    If Me![cboDepartmentID].Value <> "" Then
    deptID = Me![cboDepartmentID]
    SQLSTmt = "Select * From [tblDivision] where [DepartmentID]=" & deptID
    Set adrs = curdb.OpenRecordset(SQLSTmt, dbopendynaset)
    If adrs.EOF = True Then
    MsgBox " its not working"
    adrs.Close
    Set adrs = nohint
    curdb.Close
    Set curdb = Nothing
    Exit Sub
    Else
    'populating the second combobox based on the first one.
    Do Until adrs.EOF
    Me![cboDivisions].RowSource = "SELECT [Division] FROM [tblDivision] where [DepartmentID]=" & deptID
    adrs.MoveNext
    Loop
    adrs.Close
    Set adrs = Nothing
    curdb.Close
    Set curdb = Nothing
    End If
    End If
    Exit Sub

    --------------------------

    Thanks for the input!

  2. #2
    Join Date
    Jun 2003
    Posts
    22

    Re: 3 combo boxes........

    Originally posted by jimslim
    I have two combo boxes working fine, when you select a value from the first combo box it narrows down the selection in the second box. Now I need it to be able to narrow down a selection in the third combo box depending on the selection of the second combo box. I can't seem to get it right.

    Here is the details:

    first combo box - cboDepartmentID takes values from tblDepartment field name - Department

    2nd - cboDivisions takes values from tblDivisions, field name - Divisions

    3rd - cboSections takes values from tblSection, field name - Sections


    After update code of first combo box:

    --------------------------

    'declaration of variable
    'included DAO 3.6 library
    Dim SQLSTmt As String
    Dim curdb As Database
    Dim adrs As DAO.Recordset
    Dim deptID As Integer 'holds the Department ID number

    'portion added by vbaProgrammer
    Set curdb = CurrentDb()
    'Handling absense of value
    If Me![cboDepartmentID].Value = "" Then
    MsgBox " please select the value and try again", vbCritical, "Updating Combobox"
    Exit Sub
    End If
    'Handling the data in both combo boxes
    If Me![cboDepartmentID].Value <> "" Then
    deptID = Me![cboDepartmentID]
    SQLSTmt = "Select * From [tblDivision] where [DepartmentID]=" & deptID
    Set adrs = curdb.OpenRecordset(SQLSTmt, dbopendynaset)
    If adrs.EOF = True Then
    MsgBox " its not working"
    adrs.Close
    Set adrs = nohint
    curdb.Close
    Set curdb = Nothing
    Exit Sub
    Else
    'populating the second combobox based on the first one.
    Do Until adrs.EOF
    Me![cboDivisions].RowSource = "SELECT [Division] FROM [tblDivision] where [DepartmentID]=" & deptID
    adrs.MoveNext
    Loop
    adrs.Close
    Set adrs = Nothing
    curdb.Close
    Set curdb = Nothing
    End If
    End If
    Exit Sub

    --------------------------

    Thanks for the input!


    Never mind......... Got it working - some sloppy code but it works

Posting Permissions

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