ApplyFilter起作用,直到我点击清除按钮以清除过滤器

时间:2019-06-04 09:35:23

标签: vba ms-access access-vba

我创建了一个表单,该表单应按用户可以输入的日期进行过滤。键入所需的日期后,用户单击“限制”按钮,以便数据可以过滤这些范围。直到用户单击清除按钮,它才能正常工作。

过滤仍然有效,但在用户输入日期不起作用的情况下进行验证。它引发错误“运行时错误3000。保留的错误(-3201) 验证正在检查输入日期的天气,如果没有输入日期,则会出现一个消息框。

-这是显示日期范围的“限制按钮”-

Private Sub eingrenzen()

Dim strCriteria, task As String

'MsgBox if no entry    
' "Me.vonDatumFeld" is german and means "fromDate"    
' "Me.bisDatumFeld" means "untilDate"

Me.Refresh

If IsNull(Me.vonDatumFeld) Or IsNull(Me.bisDatumFeld) 

Then

    MsgBox "Grenzen sie bitte den Zeitraum 'von' und 'bis' ein", vbInformation, "Zeitraum eingrenzen"
    Me.vonDatumFeld.SetFocus        

Else

    strCriteria = "([Datum] >= #" & Format(Me.vonDatumFeld, "yyyy-mm-dd") & "# And [Datum] <= #" & Format(Me.bisDatumFeld, "yyyy-mm-dd") & "#)"
    task = "select * from TblTeile where (" & strCriteria & ") order by [Datum]"

    DoCmd.ApplyFilter task 'Wende ZeitraumFILTER an

End If

End Sub

-这是“清除按钮”-

Private Sub CmdLösch_Click()

Me.KIDText = vbNullString    
Me.FirmaTxt = vbNullString    
Me.DatumTxt = vbNullString    
Me.ProdArttxt = vbNullString    
Me.BeschrText = vbNullString    
Me.MaterialText = vbNullString    
Me.vonDatumFeld = vbNullString    
Me.bisDatumFeld = vbNullString    
Me.Filter = vbNullString 

Me.FilterOn = False        

Me.Requery 

End Sub

1 个答案:

答案 0 :(得分:0)

使用 Filter 方法:

strCriteria = "[Datum] >= #" & Format(Me.vonDatumFeld, "yyyy-mm-dd") & "# And [Datum] <= #" & Format(Me.bisDatumFeld, "yyyy-mm-dd") & "#"
' task = "select * from TblTeile where (" & strCriteria & ") order by [Datum]"
Me.Filter = strCriteria
Me.FilterOn = True