Forum Discussion
Using IIF and Date()
- Aug 21, 2022That tells you the result is the wrong datatype. The control is expecting one datatype, but the expression is returning a different datatype.
And, with that, I see my mistake. You want to put either a valid date or a text string ("Payment is Pending") in that control. You can't put text into a date field. You'll have to present an alternative way to signal to the user that the payment is pending, a control that does accept text.
HI George, I cant say for sure if it has something to do with as you describe above. I looked at it further and I forgot I am using a Union and on one of the queries I put "" as InvDueDate for the column since the field InvDueDate is not in that table. I think its termed "dummy" column.
Below are the columns in the Union. I am only taking a snippet of the entire code. I am not sure if its advisable to use "" as I did below but I think I must since the field is not in the table.
this is the first query in the union:
, "" AS InvDueDate,
this is the first query in the union:
,tblFXRollsChild.InvDueDate,
The correct invoice date is being returned by the Union though so to me using "" is not the issue (but it could be...see far below DateValue part) since its referring to the correct invoice date.
I dont have a format placed on the field. I do nto see a time being added to the date in the datasheet display so to me it also doesnt seem likely its due to the time as you touched on above.
Using DateValue()
I might be on to something.
=IIf(DateValue([txtInvDueDate]) Between Date() And Date()+20,"Payment is Pending","")
It returned #Type on some of the records.
It ight have something to do with me assigning "" to the InvDueDate?
What else can I do than assign a "" for a dummy column?
=IIf(CDate("0" & [txtInvDueDate]) Between Date() And Date()+20,"Payment is Pending","")
- Tony2021Aug 22, 2022Iron Contributorthank you for the tip!
I was messing around with it yesterday and I used the following (using George's datevalue technique):
=IIf(IsDate([txtInvDueDate]),DateValue([txtInvDueDate]),"")
and once I did that then that seemed to clean it up and I could use the following without getting a #type!:
=IIf([txtInvDueDate] Between Date() And DateAdd("d",15,Date()),"Payment is Pending","")
I will add your expression to my cheat sheet. thanks!