#Type! error (1 Viewer)

MAAS8000

Registered User.
Local time
Yesterday, 22:34
Joined
Apr 3, 2018
Messages
38
HELLO,
i have a form like in attached image
field C is calculated field =A/B
I have list box and I am adding records to it
the problem appear when I am trying to retrieve data in list box to the form again .If field "B" is empty in the list box the field "C" appear like in the image #Type!
the problem solved if I enter any data in field B
I tried to make re query event but no effect
 

Attachments

  • form.png
    form.png
    51.6 KB · Views: 69

CJ_London

Super Moderator
Staff member
Local time
Today, 06:34
Joined
Feb 19, 2013
Messages
16,607
probably because you are trying to divide by null value

try changing your calculation to something like

iif(nz(B,0)=0,null,A/B)
 

MAAS8000

Registered User.
Local time
Yesterday, 22:34
Joined
Apr 3, 2018
Messages
38
I have tried this but same error
=IIf(Nz(;0)=0;Null;[A]/)
 

CJ_London

Super Moderator
Staff member
Local time
Today, 06:34
Joined
Feb 19, 2013
Messages
16,607
Are A and B the names of your controls? If not, substitute them in the calculation with the real names
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:34
Joined
Oct 29, 2018
Messages
21,454
Hi. Pardon me for jumping in but what do you get with this slightly modified version of CJ's code?
Code:
=IIf(Nz([B],0)=0,Null,[A]/IIf(Nz([B],0)=0,1,[B]))
or this?
Code:
=IIf(Nz([B],0)=0,Null,[A]/Nz([B],1))
PS. I prefer the first one because it handles scenarios where is not empty but a zero (0).
 

CJ_London

Super Moderator
Staff member
Local time
Today, 06:34
Joined
Feb 19, 2013
Messages
16,607
this

Nz(,0)=0

handles both 0 and null, so returns a null value, however you have reminded me that I seem to recall the iif is evaluated in full so perhaps


iif(nz(B,0)=0,null,nz(A,0)/nz(B))
 

isladogs

MVP / VIP
Local time
Today, 06:34
Joined
Jan 14, 2017
Messages
18,209
That will work where is an empty string but not where it is null.
For that reason you do need to add Nz to handle nulls.

Either one of the earlier solutions or possibly this (if it hasn't already been posted by CJL or DBG)
Code:
=IIf(Nz([B],"")="";Null;[A]/[B])
 
Last edited:

Users who are viewing this thread

Top Bottom