iif statements

P

pigsy101

I'm trying to create a calculated field on a form that tracks stock
levels.

i have three subforms - frmOpeningStock, frmOrdered and frmAllocated.

i'm using the following statement which works fine when all fields are
populated and works when neither the Total Ordered or the Total
Allocated fields are populated.

=IIf(IsNull([frmOrdered].[Form]![Total Ordered]) And
IsNull([tblAllocated].[Form]![Total Allocated]),[frmOpeningStock].
[Form]![number],[frmOpeningStock].[Form]![number]+[frmOrdered].[Form]!
[Total Ordered]-[tblAllocated].[Form]![Total Allocated])

How can i get this to work when either the Total Ordered or the Total
Allocated could be null??

Thanks in advance

P
 
A

Al Campagna

pigsy
Try the NZ function... see Help.
=IIf(IsNull([frmOrdered].[Form]![Total Ordered]) And
IsNull([tblAllocated].[Form]![Total Allocated]),[frmOpeningStock].
[Form]![number],[frmOpeningStock].[Form]![number]+NZ([frmOrdered].[Form]!
[Total Ordered])-NZ([tblAllocated].[Form]![Total Allocated]))

--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVP
http://home.comcast.net/~cccsolutions

"Find a job that you love, and you'll never work a day in your life."

pigsy101 said:
I'm trying to create a calculated field on a form that tracks stock
levels.

i have three subforms - frmOpeningStock, frmOrdered and frmAllocated.

i'm using the following statement which works fine when all fields are
populated and works when neither the Total Ordered or the Total
Allocated fields are populated.

=IIf(IsNull([frmOrdered].[Form]![Total Ordered]) And
IsNull([tblAllocated].[Form]![Total Allocated]),[frmOpeningStock].
[Form]![number],[frmOpeningStock].[Form]![number]+[frmOrdered].[Form]!
[Total Ordered]-[tblAllocated].[Form]![Total Allocated])

How can i get this to work when either the Total Ordered or the Total
Allocated could be null??

Thanks in advance

P
 
G

Guest

I don't think you need to call the IIf function at all, do you? A simple
expression returning zeros where the controls are Null should give the same
result:

=[frmOpeningStock].[Form]![number]+Nz([frmOrdered].[Form]![Total
Ordered],0)-Nz([tblAllocated].[Form]![Total Allocated],0)

Ken Sheridan
Stafford, England
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top