Using DCount in a IIF statement (1 Viewer)

atrium

Registered User.
Local time
Today, 20:16
Joined
May 13, 2014
Messages
348
I'm using the following

Code:
=IIf([TranSType]=2,DCount("[DocId]","DocumentLibrary","[TransType] = 1 And [FolderName] = '" & [FolderFld] & "' AND [ClientId] = & [ClientIdFld] & "),"N/A")

to fill a filed on a form. TransType = numeric, FolderName = String, ClientId = Numeric

This is a continuous form and for every TransType = 2 I get the #error and for the TransTypes 1 I get N/A placed in the field

Any help would be appreciated
 

isladogs

MVP / VIP
Local time
Today, 09:16
Joined
Jan 14, 2017
Messages
18,186
Change it to .... AND [ClientId] = " & [ClientIdFld]) assuming its a number field

Code:
=IIf([TranSType]=2,DCount("[DocId]","DocumentLibrary","[TransType] = 1 And [FolderName] = '" & [FolderFld] & "' AND [ClientId] = " & [ClientIdFld]),"N/A")

However using DCount and IIF for every record in a query will be slow.
Better to join tables so you can get rid of the domain function
 
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Today, 02:16
Joined
Oct 29, 2018
Messages
21,358
Hi. If TranSType=2, what did you expect to get? True or False?
 

atrium

Registered User.
Local time
Today, 20:16
Joined
May 13, 2014
Messages
348
Thanks guys, Syntax beat me again.
;)

Thank you for all of your help
 

isladogs

MVP / VIP
Local time
Today, 09:16
Joined
Jan 14, 2017
Messages
18,186
Happy to help. Do you now have working code?
 

Users who are viewing this thread

Top Bottom