Public filter_text As String '定义为公共变量,今天小编就来聊一聊关于access 使用vba查询数据如何保存?接下来我们就一起去研究一下吧!
access 使用vba查询数据如何保存
Public filter_text As String '定义为公共变量
Private Sub Command查询_Click()
filter_text = ""
If Me.员工编号 <> "" Then
If filter_text <> "" Then
filter_text = filter_text & " and 员工编号 like '*" & Me.员工编号 & "*'"
Else
filter_text = "员工编号 like '*" & Me.员工编号 & "*'"
End If
End If
If Me.部门 <> "" Then
If filter_text <> "" Then
filter_text = filter_text & " and 部门 like '*" & Me.部门 & "*'"
Else
filter_text = "部门 like '*" & Me.部门 & "*'"
End If
End If
If Me.职位 <> "" Then
If filter_text <> "" Then
filter_text = filter_text & " and 职位 like '*" & Me.职位 & "*'"
Else
filter_text = "职位 like '*" & Me.职位 & "*'"
End If
End If
If Me.姓名 <> "" Then
If filter_text <> "" Then
filter_text = filter_text & " and 姓名 like '*" & Me.姓名 & "*'"
Else
filter_text = "姓名 like '*" & Me.姓名 & "*'"
End If
End If
If Me.销售日期1 <> "" And Me.销售日期2 <> "" Then
If filter_text <> "" Then
filter_text = filter_text & " and 销售日期 between #" & Me.销售日期1 & "# and #" & Me.销售日期2 & "#"
Else
filter_text = "销售日期 between #" & Me.销售日期1 & "# and #" & Me.销售日期2 & "#"
End If
End If
If Me.销售额1 <> "" And Me.销售额2 <> "" Then
If filter_text <> "" Then
filter_text = filter_text & " and 销售额 >= " & Me.销售额1 & " and 销售额<=" & Me.销售额2
Else
filter_text = "销售额 >= " & Me.销售额1 & " and 销售额<=" & Me.销售额2
End If
End If
'------------------------------筛选子窗体
If filter_text <> "" Then
Me.数据表子窗体.Form.Filter = filter_text
Me.数据表子窗体.Form.FilterOn = True
Else
Me.数据表子窗体.Form.FilterOn = False
End If
End Sub
Private Sub Command清空_Click()
员工编号.Value = ""
姓名.Value = ""
部门.Value = ""
职位.Value = ""
销售日期1.Value = ""
销售日期2.Value = ""
销售额1.Value = ""
销售额2.Value = ""
End Sub
Private Sub Command全部_Click()
Me.数据表子窗体.Form.FilterOn = False
End Sub
,