If the IIf is in the ControlSource property of a text box on the same form as the frmdischarge form, you don't need to specify the form.
If it IIf is in the underlying query, don't reference the form. Reference the query's recordsource if that is where ddate is to be found.
Using a data item that depends on a form absolutely requires that the form must be open at the time you reference the data item. Not just defined. Open. (And not in Design View, either.)
Let's say the record looks like this:
myTable:
- DDate (date field)
- ADate (date field)
- lots of other data
The query that would populate this item could be as simple as:
myQuery1 (based on myTable)
for the date difference query field, and with the line broken out into parts to show exact punctuation...
Expr1: IIf(
IsNull( [DDate] ),
DateDiff( "d", [ADate], Date() ),
DateDiff( "d", [ADate], [DDate] )
)
Then Expr1 should be a number of days.
Alternatively, if this is ONLY useful for a form then you could put the SAME EXACT IIF STATEMENT as the controlsource for the text box that shows the number of days on the form. Of course, you must set that text box to Locked=True if it is based on an expression.