This is called cascading combo boxes.
Originally Posted by
tbassngal
Private Sub cboDefectDescription_AfterUpdate(Cancel As Integer)
Me.cboSubDefect.RowSource = "SELECT SubDefect FROM" & _
" tblSubDefect WHERE [Defect Description] = " & Me.[cboDefectDescription] & _
" ORDER BY SubDefect"
Me.cboSubDefect = Me.cboSubDefect.ItemData(0)
End Sub
Because you are using a text field to 'link' the two tables, the value from cboDefectDescription needs to be delimited with quotes. Look closely at the following WHERE caluse:
Code:
Private Sub cboDefectDescription_AfterUpdate(Cancel As Integer)
Me.cboSubDefect.RowSource = "SELECT SubDefect FROM" & _
" tblSubDefect WHERE [Defect Description] = '" & Me.[cboDefectDescription] & _
"' ORDER BY SubDefect"
'the requery may not be necessary, but I use it
Me.cboSubDefect.Requery
Me.cboSubDefect = Me.cboSubDefect.ItemData(0)
End Sub
Additionally, I don't even want the box to be active if there are no subDefects. I want the value to be *.
Which "box" shouldn't be active?
Note: you shouldn't use spaces in object names. It will cause you headaches when you create queries, forms and/or reports.