前沿拓展:
access數(shù)據(jù)庫(kù)
數(shù)據(jù)庫(kù),顧名思義:數(shù)據(jù)的倉(cāng)庫(kù)。
當(dāng)使用者需要保存的數(shù)據(jù)量不是很大時(shí),我們可以直接將數(shù)據(jù)寫到編輯完全可視化,且內(nèi)置強(qiáng)大的Office編程環(huán)境VBA,無(wú)需第三方編程軟件,即可迅速開發(fā)桌面數(shù)據(jù)庫(kù)系統(tǒng)。
Public filter_text As String '定義為公共變量
Private Sub Command查詢_Click()
filter_text = ""
If Me.員工編號(hào) <> "" Then
If filter_text <> "" Then
filter_text = filter_text & " and 員工編號(hào) like '*" & Me.員工編號(hào) & "*'"
Else
filter_text = "員工編號(hào) like '*" & Me.員工編號(hào) & "*'"
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.數(shù)據(jù)表子窗體.Form.Filter = filter_text
Me.數(shù)據(jù)表子窗體.Form.FilterOn = True
Else
Me.數(shù)據(jù)表子窗體.Form.FilterOn = False
End If
End Sub
Private Sub Command清空_Click()
員工編號(hào).Value = ""
姓名.Value = ""
部門.Value = ""
職位.Value = ""
銷售日期1.Value = ""
銷售日期2.Value = ""
銷售額1.Value = ""
銷售額2.Value = ""
End Sub
Private Sub Command全部_Click()
Me.數(shù)據(jù)表子窗體.Form.FilterOn = False
End Sub
拓展知識(shí):
前沿拓展:
access數(shù)據(jù)庫(kù)
數(shù)據(jù)庫(kù),顧名思義:數(shù)據(jù)的倉(cāng)庫(kù)。
當(dāng)使用者需要保存的數(shù)據(jù)量不是很大時(shí),我們可以直接將數(shù)據(jù)寫到編輯完全可視化,且內(nèi)置強(qiáng)大的Office編程環(huán)境VBA,無(wú)需第三方編程軟件,即可迅速開發(fā)桌面數(shù)據(jù)庫(kù)系統(tǒng)。
Public filter_text As String '定義為公共變量
Private Sub Command查詢_Click()
filter_text = ""
If Me.員工編號(hào) <> "" Then
If filter_text <> "" Then
filter_text = filter_text & " and 員工編號(hào) like '*" & Me.員工編號(hào) & "*'"
Else
filter_text = "員工編號(hào) like '*" & Me.員工編號(hào) & "*'"
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.數(shù)據(jù)表子窗體.Form.Filter = filter_text
Me.數(shù)據(jù)表子窗體.Form.FilterOn = True
Else
Me.數(shù)據(jù)表子窗體.Form.FilterOn = False
End If
End Sub
Private Sub Command清空_Click()
員工編號(hào).Value = ""
姓名.Value = ""
部門.Value = ""
職位.Value = ""
銷售日期1.Value = ""
銷售日期2.Value = ""
銷售額1.Value = ""
銷售額2.Value = ""
End Sub
Private Sub Command全部_Click()
Me.數(shù)據(jù)表子窗體.Form.FilterOn = False
End Sub
拓展知識(shí):
原創(chuàng)文章,作者:九賢生活小編,如若轉(zhuǎn)載,請(qǐng)注明出處:http://xiesong.cn/37974.html