|
如何在ACCESS中利用复选框进行多条件筛选?
建立表、主子窗子的过程在此不多说了,直接进入正题。
1、根据3个条件创建3个复选框,并设置属性;
2、创建筛选按钮,并在属性的单击事件中添加代码如下:- Private Sub 筛选_Button_Click()
- If tj1 And tj2 And tj3 Then
- 表1.Form.RecordSource = "select * from 表1"
- End If
- If tj1 And tj2 And tj3 = False Then
- 表1.Form.RecordSource = "select * from 表1 where 达标率<80"
- End If
- If tj1 And tj2 = False And tj3 Then
- 表1.Form.RecordSource = "select * from 表1 where 达标率<50 OR 达标率>=80"
- End If
- If tj1 And tj2 = False And tj3 = False Then
- 表1.Form.RecordSource = "select * from 表1 where 达标率<50"
- End If
- If tj1 = False And tj2 And tj3 Then
- 表1.Form.RecordSource = "select * from 表1 where 达标率>=50 OR 达标率>=80"
- End If
- If tj1 = False And tj2 And tj3 = False Then
- 表1.Form.RecordSource = "select * from 表1 where 达标率>=50 and 达标率<80"
- End If
- If tj1 = False And tj2 = False And tj3 Then
- 表1.Form.RecordSource = "select * from 表1 where 达标率>=80"
- End If
- If tj1 = False And tj2 = False And tj3 = False Then
- 表1.Form.RecordSource = "select * from 表1"
- End If
- 表1.Form.Requery
- End Sub
复制代码 3、在窗体加载事件中添加代码如下:- Private Sub Form_Load()
- DoCmd.Restore
- End Sub
复制代码 4、保存、调试运行,筛选效果如下动画所示:
|
|