Hi!
I am trying to create a if/then statement using MS VBA and an SQL statement to update a new field based on the dates of the current date field. I thought that the code I had written would work well but when I try to run it I get an error saying there are an invalid number of arguments.
This is the code I am trying to run:
I think the if statements are relatively straightforward and the maxdate variable is supposed to be finding the most recent date in the Closed Date field.
If someone is able to make a suggestion as to what the issue may be that would be most appreciated.
Thanks so much!
David
I am trying to create a if/then statement using MS VBA and an SQL statement to update a new field based on the dates of the current date field. I thought that the code I had written would work well but when I try to run it I get an error saying there are an invalid number of arguments.
This is the code I am trying to run:
Code:
Dim maxdate As DateDim strSQLdt As String
maxdate = DMax("[Closed Date]", "tblHPILTV")
strSQLst = "Update tblHPILTV " _
& "SET tblHPILTV.[Updated Close Date] = IIF([Closed Date] Is Null," _
& "DATE(2008,7,1),IIF([Closed Date]>" & maxdate & "," & maxdate & ",IIF(MONTH([Closed Date])<=3," _
& "DATE(YEAR([Closed Date]),1,1),IIF(MONTH([Closed Date])<=6,DATE(YEAR([Closed Date]),4,1)," _
& "IIF(MONTH([Closed Date])<=9,DATE(YEAR([Closed Date]),7,1),DATE(YEAR([Closed Date]),10,1))))));"
DoCmd.RunSQL (strSQLst)
I think the if statements are relatively straightforward and the maxdate variable is supposed to be finding the most recent date in the Closed Date field.
If someone is able to make a suggestion as to what the issue may be that would be most appreciated.
Thanks so much!
David