在窗体中创建了一个子窗体,然后在组合框的更新后事件中加入如下代码即可实现你要求的功能。具体参考附件。
点击下载此附件
Private Sub Combo0_AfterUpdate()
Dim i, j
Dim s1, s2
For i = 0 To Me.考评表查询.Form.Controls.Count - 1
If Me.考评表查询.Form.Controls(i).ControlType = acCheckBox Then
Me.考评表查询.Form.Controls(i).ColumnHidden = True
End If
Next i
For i = 0 To Me.考评表查询.Form.Controls.Count - 1
If Me.考评表查询.Form.Controls(i).ControlType = acCheckBox And Me.考评表查询.Form.Controls(i).Name = Combo0 Then
Me.考评表查询.Form.Controls(i).ColumnHidden = False
End If
j = InStr(1, Combo0, ":")
If j > 0 And Me.考评表查询.Form.Controls(i).ControlType = acCheckBox Then
s1 = Left(Combo0, 1)
s2 = Right(Combo0, 1)
If Me.考评表查询.Form.Controls(i).Name >= s1 And Me.考评表查询.Form.Controls(i).Name <= s2 Then
Me.考评表查询.Form.Controls(i).ColumnHidden = False
End If
End If
Next i
End Sub
窗体的打开事件中的代码:
Private Sub Form_Open(Cancel As Integer)
Dim i
For i = 0 To Me.考评表查询.Form.Controls.Count - 1
If Me.考评表查询.Form.Controls(i).ControlType = acCheckBox Then
Me.考评表查询.Form.Controls(i).ColumnHidden = False
End If
Next i
End Sub