|
|
Фильтрация подчинённой формы по трём иерархическим ComboBox-ам (+ Пример)
Простой, но (надеюсь) наглядный пример:
Каскадная фильтрация подчинённой формы по трём иерархически связанным полям со списком, одной процедурой.
Private Sub cbGood_AfterUpdate()
esFormUpd 3
End Sub
Private Sub cbManufacturer_AfterUpdate()
esFormUpd 2
End Sub
Private Sub cbType_AfterUpdate()
esFormUpd 1
End Sub
Private Sub cmdClearGood_Click()
Me!cbGood = Null
esFormUpd 3
End Sub
Private Sub cmdClearManufacturer_Click()
Me!cbManufacturer = Null
esFormUpd 2
End Sub
Private Sub cmdClearType_Click()
Me!cbType = Null
esFormUpd 1
End Sub
Private Sub esFormUpd(updPoint As Integer)
On Error GoTo esFormUpdErr
Select Case updPoint
Case 1: GoTo Point001
Case 2: GoTo Point002
Case 3: GoTo Point003
End Select
Point001:
Me!cbManufacturer = Null
If IsNull(Me!cbType) = False Then
Me!cbManufacturer.Enabled = True
Me!cbManufacturer.Requery
Me!cbManufacturer.SetFocus
Else
Me!cbManufacturer.Enabled = False
End If
Point002:
Me!cbGood = Null
If IsNull(Me!cbManufacturer) = False Then
Me!cbGood.Enabled = True
Me!cbGood.Requery
Me!cbGood.SetFocus
Else
Me!cbGood.Enabled = False
End If
Point003:
FilterSubForm
esFormUpdBye:
Exit Sub
esFormUpdErr:
MsgBox "Error " & Err.Number & vbCrLf & Err.Description & vbCrLf & _
"in procedure esFormUpd of VBA Document Form_000Order", vbCritical, "Error!"
Resume esFormUpdBye
End Sub
Private Sub FilterSubForm()
Dim strFilter As String
On Error GoTo FilterSubFormErr
If IsNull(Me!cbType) = False Then
strFilter = " AND PTypeID = " & Me!cbType
End If
If IsNull(Me!cbManufacturer) = False Then
strFilter = strFilter & " AND ManufacturerID = " & Me!cbManufacturer
End If
If IsNull(Me!cbGood) = False Then
strFilter = strFilter & " AND GoodID = " & Me!cbGood
End If
If Not strFilter = "" Then
strFilter = Mid(strFilter, 6)
Me!objSubForm.Form.Filter = strFilter
Me!objSubForm.Form.FilterOn = True
Else
Me!objSubForm.Form.Filter = ""
Me!objSubForm.Form.FilterOn = False
End If
FilterSubFormBye:
Exit Sub
FilterSubFormErr:
MsgBox "Error " & Err.Number & vbCrLf & Err.Description & vbCrLf & _
"in procedure FilterSubForm of VBA Document Form_000Order", vbCritical, "Error!"
Resume FilterSubFormBye
End Sub
MSA-2003 ( 120 kB) Пример
|
|