Reputation: 38956
In Access 2007 The code below gives Error 2434: The expression you entered contains invalid syntax.
If (Eval("DLookUp(""[BaseRate]"",""RATELOOKUP"",""|DatePart(""yyyy"",[TxDate])| & |DatePart(""m"",[TxDate])| = [RATELOOKUP].[PERIOD]"") Is Null")) Then
' Checks for Current Base Rate
Beep
MsgBox "Interest Rate required for this month", vbExclamation, ""
End If
The error appears to be in the first line.
Upvotes: 1
Views: 962
Reputation: 97101
Proper quoting within the string expression you give to Eval()
can be very challenging. Here is what Eval()
actually sees within your code:
DLookUp("[BaseRate]","RATELOOKUP","|DatePart("yyyy",[TxDate])| & |DatePart("m",[TxDate])| = [RATELOOKUP].[PERIOD]") Is Null
Consider a different approach when using Eval()
, one which allows you to see exactly what you're asking Eval()
to evaluate.
Dim strEval As String
strEval = "your expression here"
Debug.Print strEval ' <- examine the string Eval() receives
' finally ...
If Eval(strEval) ...
However, this thing looks way too complicated to me, so I suspect there should be a simpler solution which doesn't even require Eval()
. Unfortunately your DLookup
Criteria argument is so confusing I got lost. But I suspect the IsNull()
function might give you what you want without needing Eval()
:
If IsNull(DLookup("BaseRate","RATELOOKUP", "your Criteria here")) = True Then
Upvotes: 2