I have a set of five cascading combo boxes, the first of which gets its data from a table, say table1, with the rest getting their data from SQL queries run against table2, table3 etc. So if the first combo box lists item1, item2, item3, item4 etc., and item3 is selected then the second combo box will only list the items in table2 that the SQL query associates with item3. The third combo box lists only those items in table3 that the SQL query associates with the selected item in the third combo box.
This all works fine until there were no items available as a result of one of the SQL queries. I am trying to find a way of ending the process gracefully bit so far I cannot find a way of doing this if an intermediate query results in a zero length list.
I have tried to upload an example database but even my cut down version was too large!
If I could get the code below working I think it would solve my problem. I am using the Got focus event to check that the listcount is zero and if it is zero to set the Me.Classification combo box state to enabled = false. This works but returns to the after update sub and tries to set the focus which, of course, doesn't work because the state of the combo box in question is now set to enabled = false. The "if" statement shown on bold returns True irrespective of the enabled state i.e., if enabled is set to False the conditional statement is still executed hence an error is generated.
Any help would be appreciated.
Code:
Private Sub Classification_GotFocus()
MsgBox "Classification has got Focus"
With Me.Classification
.Requery
MsgBox "Number of items in the list= " & Me.Classification.ListCount
If .ListCount = 0 Then
.Enabled = False
Else
.Enabled = True
End If
End With
End Sub
Code:
Private Sub Category_AfterUpdate()
vCategory = Category.Text: Debug.Print "Category = " & vCategory
With Me.Classification
.Requery
.Value = ""
.Enabled = True
If .Enabled = True Then 'If the listcount is zero then Me.Classification will have .Enabled set to False.
MsgBox "Enabled = " & .Enabled
.SetFocus
End If
End With
With Me.Group
.Requery
.Value = ""
.Enabled = False
End With
With Me.Topic
.Requery
.Value = ""
.Enabled = False
End With
With Me.Subject
.Requery
.Value = ""
.Enabled = False
End With
End Sub