我得到了下面的函数返回一个字符串:之间#2009年/ 01/01#和#2015/07/28#如何使用函数(返回一个字符串)作为查询条件?
Public Function PayrollDateGet() As String
'get dates
'test for null
If IsNull(PStartD) = True Or IsNull(PEndD) = True Then
MsgBox "Please set the payroll parameters first by calling the PayrollAgentSet() function"
Exit Function
Else
PayrollDateGet = CStr("Between #" & PStartD & "# And #" & PEndD & "#")
End If
End Function
我想用这个字符串作为查询条件的日期字段像这样:
SELECT TestTblD.ID, TestTblD.Ddate, TestTblD.TestValue
FROM TestTblD
WHERE (((TestTblD.Ddate)=PayrollDateGet()));
错误:在条件表达式
数据类型不匹配阅读此线程后:我是铅相信正则表达式是我所追求的,但我不知道如何使用它Expressing basic Access query criteria as regular expressions?这里是一个尝试,只返回一个真正的值,而不是一个SQL查询可以使用的代码:
Public Function PayrollDateGet() As String
'get dates
'test for null
If IsNull(PStartD) = True Or IsNull(PEndD) = True Then
MsgBox "Please set the payroll paramaters first by calling the PayrollAgentSet() funciton"
Exit Function
Else
'create the sting
Dim pattern As String
pattern = CStr("Between #" & PStartD & "# And #" & PEndD & "#")
' Initialise the Regex object '
Static regex As Object
If regex Is Nothing Then
Set regex = CreateObject("vbscript.regexp")
With regex
.Global = True
.IgnoreCase = True
.MultiLine = True
End With
End If
' Update the regex pattern if it has changed since last time we were called '
If regex.pattern <> pattern Then regex.pattern = pattern
' Test the value against the pattern '
PayrollDateGet = regex.Test(pattern)
End If
End Function
任何想法?
仍然没有工作,但接近,如果你走过代码它贯穿一切,返回三个真实的,但是当它打开该查询没有记录显示。如果我手动在[Ddate]字段中输入true,则显示3条记录。 – Rhdr
如果您将这三个值手动输入到函数中,它会返回什么? – Gustav
不要在意我的sql中有错误我错过了=真正的部分...它的作品谢谢你 – Rhdr