導航窗體
Private Sub Command打開_Click()
DoCmd.OpenForm "單記錄綁定窗體查詢", acNormal, , "所在部門='" & Me.Text部門 & "'"
End Sub
Private Sub Command打開列表_Click()
DoCmd.OpenForm "員工列表", acNormal, , "所在部門='" & Me.所在部門 & "'"
End Sub
Private Sub Command數據表_Click()
DoCmd.OpenForm "員工數據表", acFormDS, , "所在部門='" & Me.所在部門 & "'"
End Sub
多條件篩選查詢Private Sub Command查詢_Click()
DoCmd.OpenQuery "員工條件查詢", acViewNormal
End Sub
Private Sub Command查詢2_Click()
DoCmd.OpenForm "員工條件查詢數據表", acFormDS
End Sub
多條件篩選查詢2Public 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 所在部門 = '" & Me.所在部門 & "'"
Else
filter_text = "所在部門 = '" & Me.所在部門 & "'"
End If
End If
If Me.工齡 <> "" Then
If filter_text <> "" Then
filter_text = filter_text & " and 工齡 >=" & Me.工齡
Else
filter_text = "工齡 >=" & 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 filter_text <> "" Then
DoCmd.OpenForm "員工列表", acNormal, , filter_text
Else
DoCmd.OpenForm "員工列表", acNormal
End If
End Sub
列表框篩選Private Sub Command部門_Click()
Me.員工查詢列表.RowSource = "Select 員工号,姓名,性别,所在部門,職位,工齡 From 員工表 Where 所在部門 like '*" & InputBox("請輸入所在部門", "按部門查詢") & "*'"
End Sub
Private Sub Command姓名_Click()
Me.員工查詢列表.RowSource = "Select 員工号,姓名,性别,所在部門,職位,工齡 From 員工表 Where 姓名 like '*" & InputBox("請輸入姓名", "按姓名查詢") & "*'"
End Sub
Private Sub Command員工号_Click()
Me.員工查詢列表.RowSource = "Select 員工号,姓名,性别,所在部門,職位,工齡 From 員工表 Where 員工号 = '" & InputBox("請輸入員工号", "按員工号查詢") & "'"
End Sub
Private Sub Command職位_Click()
Me.員工查詢列表.RowSource = "Select 員工号,姓名,性别,所在部門,職位,工齡 From 員工表 Where 職位 like '*" & InputBox("請輸入現聘職務", "按現聘職務查詢") & "*'"
End Sub
員工列表框多條件查詢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 所在部門 = '" & Me.所在部門查詢 & "'"
Else
filter_text = "所在部門 = '" & Me.所在部門查詢 & "'"
End If
End If
If Me.工齡查詢 <> "" Then
If filter_text <> "" Then
filter_text = filter_text & " and 工齡 >=" & Me.工齡查詢
Else
filter_text = "工齡 >=" & 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 filter_text <> "" Then
Me.Filter = filter_text
Me.FilterOn = True
Else
Me.FilterOn = False
End If
End Sub
Private Sub Command全部_Click()
Me.FilterOn = False
End Sub
員工篩選子窗體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 所在部門 = '" & Me.所在部門查詢 & "'"
Else
filter_text = "所在部門 = '" & Me.所在部門查詢 & "'"
End If
End If
If Me.工齡查詢 <> "" Then
If filter_text <> "" Then
filter_text = filter_text & " and 工齡 >=" & Me.工齡查詢
Else
filter_text = "工齡 >=" & 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 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()
Me.員工數據表.Form.FilterOn = False
End Sub
,更多精彩资讯请关注tft每日頭條,我们将持续为您更新最新资讯!