我想在where子句中使用日期。我正在建立这样的子句:哪里条件与数据访问
WhereCondition = WhereCondition + "DOB =" + DOB.value
DoCmd.OpenForm "InputForm", , , WhereCondition
DOB是当前形式的文本框。我得到的错误类型不匹配在以下行:
WhereCondition = WhereCondition + "DOB =" + DOB.value
什么问题,我该如何解决它?
我想在where子句中使用日期。我正在建立这样的子句:哪里条件与数据访问
WhereCondition = WhereCondition + "DOB =" + DOB.value
DoCmd.OpenForm "InputForm", , , WhereCondition
DOB是当前形式的文本框。我得到的错误类型不匹配在以下行:
WhereCondition = WhereCondition + "DOB =" + DOB.value
什么问题,我该如何解决它?
首先,要对VBA的连接运算符是符号,而不是一个+号。
所以,你应该建立您的字符串是这样的:
WhereCondition = WhereCondition & "DOB =" & DOB.value
DoCmd.OpenForm "InputForm", , , WhereCondition
如果这不起作用,它可能需要换你的约会磅。
WhereCondition = WhereCondition & "DOB =#" & DOB.value & "#"
DoCmd.OpenForm "InputForm", , , WhereCondition
它有助于使用#传递日期:
WhereCondition = WhereCondition & "DOB =#" & DOB.value & "#"
下面是我用:
Dim mySQL as string, WStr as string
mySQL = "DELETE * FROM table"
WStr = " WHERE table.DOB = #" & Forms.*form name*.*control name*.value & "#"
'this will get the value from the form field
mySQL = mySQL & WStr
DoCmd.SetWarnings False 'Prevents message box
DoCmd.runSQL mySQL
DoCmd.SetWarnings True
当然,你不必实际运行查询,你可以分配一个动态查询字符串作为一个下拉记录源 - 这将不过需要成为一个SELECT查询。