我得到了下面的函數返回一個字符串:之間#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