×

Loading...
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务

I am testing whether it has anything to do with NULL value. I need to modify permanent query behind a form:

Private Sub ComboDate_AfterUpdate()
Dim qdf as QueryDef, strSQL as String
Set qdf=CurrentDB().QueryDefs("query name")
strSQL="SELECT * FROM [table name] WHERE [date field]=#" _
& Me!ComboDate & "#"
qdf.SQL=strSQL
End Sub

This code successfully changes the SQL of the query. But when I try to run the query, that mismatch message pops up.

Sometime it works and sometime it doesn't. It seams that it didn't work when [date field] contained NULL value. Any advice?
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / 有没有MS Access的牛人?用date field 做key的query时遇到 "date type mismatch" 的 message 是怎么回事?明明两边都是日期。尤其是用DateSerial()时更易出现。现在一见date key就发醋。请点拨一二。
    • 是不是因为你日期的格式不对?
      比方说应该用:
      select * from mytable where mydate=#2003/10/22#
      而不能用:
      select * from mytable where mydate="2003/10/22"
      • I am testing whether it has anything to do with NULL value. I need to modify permanent query behind a form:
        Private Sub ComboDate_AfterUpdate()
        Dim qdf as QueryDef, strSQL as String
        Set qdf=CurrentDB().QueryDefs("query name")
        strSQL="SELECT * FROM [table name] WHERE [date field]=#" _
        & Me!ComboDate & "#"
        qdf.SQL=strSQL
        End Sub

        This code successfully changes the SQL of the query. But when I try to run the query, that mismatch message pops up.

        Sometime it works and sometime it doesn't. It seams that it didn't work when [date field] contained NULL value. Any advice?
        • beats me.
        • I also have this problem, so everytime I check the value first, if is not NULL, I will exeute the query, otherwise not....