Solved Count and Display N/A

Valient

Member
Local time
Today, 11:11
Joined
Jun 21, 2021
Messages
48
Hi Team,

Can you please help me.

I'm using the code : =Count([ProductA])

To count all ProductA. However, when there is no ProductA in the list it display zero (0).
Can someone help me to improve my code to display N/A instead of zero when no ProductA available
 
I'm surprised you get any results--Count is not a function in Access. It is a function in SQL, however your code is clearly not that. Most likely you want to use DCOUNT:


Check that link out it tells you exactly how to use the function.

However, I fear you have bigger issues if you have a field called 'ProductA'. Most likely you have not set up your tables correctly. Field names should not be that specific. The 'A' part shoudl go into a field named 'ProductType' and then whatever you are currently storing in the field 'ProductA' should go into a different field.

Before you move on to solving this count issue, I suggest you complete and post a screenshot of the Relationship Tool in Access so we can help you properly strucutre this database.
 
I'm surprised you get any results--Count is not a function in Access. It is a function in SQL, however your code is clearly not that. Most likely you want to use DCOUNT:


Check that link out it tells you exactly how to use the function.

However, I fear you have bigger issues if you have a field called 'ProductA'. Most likely you have not set up your tables correctly. Field names should not be that specific. The 'A' part shoudl go into a field named 'ProductType' and then whatever you are currently storing in the field 'ProductA' should go into a different field.

Before you move on to solving this count issue, I suggest you complete and post a screenshot of the Relationship Tool in Access so we can help you properly strucutre this database.
Thanks for the response.

I put the code in Control Source, Under Data.
 
I think I get it now. Count will work in the headers and footers of reports/forms.

What you need to do is employee and IIF statement instead of the count:

=if(Count([ProductA])=0, "N/A", Count([ProductA]))

I still think you need to evaluate your table structure though.
 
I think I get it now. Count will work in the headers and footers of reports/forms.

What you need to do is employee and IIF statement instead of the count:

=if(Count([ProductA])=0, "N/A", Count([ProductA]))

I still think you need to evaluate your table structure though.
Hi plog,

You are right, I did the code in report.
I tried the suggested code but it display the word "%NAMES" not the target "N/A"
 
I think I missed an i. Try this:

=iif(Count([ProductA])=0, "N/A", Count([ProductA]))
 
You can just use =Count([FieldName]) as the ControlSource, and then edit the Format property of the textbox, which provides four-part formats for positive; negative; zero; null values that textbox may contain.
 
I think I missed an i. Try this:

=iif(Count([ProductA])=0, "N/A", Count([ProductA]))
Thank you.

I tried the code but it pop up with missing symbol, however when I change the "iif" to "IIf" it works.

=IIf(Count([ProductA])=0, "N/A", Count([ProductA]))
 
iif works just fine, so no idea as to what you were doing?

? iif(Date = date,"True","False")
True
 
iif works just fine, so no idea as to what you were doing?

? iif(Date = date,"True","False")
True
This one doesnt work: =iif(Count([ProductA])=0, "N/A", Count([ProductA]))

This works: =IIf(Count([ProductA])=0, "N/A", Count([ProductA]))

Also, I'm not an expert to this access field. The DB is created by an expert guy and there is no more support.
I'm just adding more function and thanks to this forum who helps me a lot.
 
vba is not case sensitive so there should be no difference between 'iif' and IIf'

It is generally a bad idea to mix datatypes in the same column, plus in this example you are executing count twice so will have a (possibly small) hit on performance.

Personally I would use the format property as MarkK suggested in post #9 - it would be

;;"N/A"
 

Users who are viewing this thread

Back
Top Bottom