MS access 中子表单上的日期和类别之间的多重过滤器 >> 类型不匹配错误

问题描述 投票:0回答:1

请任何人建议我解决这个错误,我是 MS Access 开发的新手。我在过滤日期和类别之间过滤子表单时遇到问题。它显示“类型不匹配”的错误语句。我尝试了很多,但无法解决这个问题。源代码如下所示。

====================================================== =========================================== 私有子 btn_SearchFilter_Click()

将 FilterDate、FilterCategory 设置为字符串

我.刷新 如果 IsNull(Me.filter_DateStart) 或 IsNull(Me.filter_DateEnd) 或 IsNull(Me.filter_ContourCategory) 那么 MsgBox "请输入值", vbCritical, "错误通知" Me.filter_DateStart.SetFocus

Else
    FilterDate = "[Cont_RegisterDate] Between #" & Me!filter_DateStart.Value & "# And #" & Me!filter_DateEnd.Value & "#"
    FilterCategory = "Cont_Category='" & Me.filter_ContourCategory.Value & "'"
    Me!ContourRegisterSub.Form.Filter = FilterDate And FilterCategory
    Me!ContourRegisterSub.Form.FilterOn = True
    

结束如果

结束子

结果:错误“语法不匹配”<< ==========================================================================================

但是,如果我尝试仅过滤一个字符串(FilterDate 或 FilterCategory),它可以过滤,如下所示。

====================================================== ===========================================

私有子btn_SearchFilter_Click()

将 FilterDate 调暗为字符串

我.刷新 如果 IsNull(Me.filter_DateStart) 或 IsNull(Me.filter_DateEnd) 那么 MsgBox "请输入值", vbCritical, "错误通知" Me.filter_DateStart.SetFocus

Else
    FilterDate = "[Cont_RegisterDate] Between #" & Me!filter_DateStart.Value & "# And #" & Me!filter_DateEnd.Value & "#"
    Me!ContourRegisterSub.Form.Filter = FilterDate
    Me!ContourRegisterSub.Form.FilterOn = True
    

结束如果

结束子

结果:能够过滤日期<<

私有子btn_SearchFilter_Click()

将 FilterCategory 调暗为字符串

我.刷新 如果 IsNull(Me.filter_ContourCategory) 那么 MsgBox "请输入值", vbCritical, "错误通知" Me.filter_ContourCategory.SetFocus

Else
    FilterCategory = "Cont_Category='" & Me.filter_ContourCategory.Value & "'"
    Me!ContourRegisterSub.Form.Filter = FilterCategory
    Me!ContourRegisterSub.Form.FilterOn = True
    

结束如果

结束子

结果:能够过滤类别<<

====================================================== ===========================================

任何人都可以帮助我或建议我解决这个问题,我会很高兴。

vba database ms-access filter type-mismatch
1个回答
0
投票

您必须串联过滤条件:

Else
    FilterDate = "[Cont_RegisterDate] Between #" & Format(Me!filter_DateStart.Value, "yyyy\/mm\/dd") & "# And #" & Format(Me!filter_DateEnd.Value, "yyyy\/mm\/dd") & "#"
    FilterCategory = "Cont_Category='" & Me!filter_ContourCategory.Value & "'"
    Me!ContourRegisterSub.Form.Filter = FilterDate & " And " & FilterCategory
    Me!ContourRegisterSub.Form.FilterOn = True
© www.soinside.com 2019 - 2024. All rights reserved.