Count records in subform

maxgold

New member
Local time
Today, 23:40
Joined
Jan 28, 2022
Messages
20
Hello,

I am trying to either hide a subform if it contains no records using a macro, since unfortunately my place of work does not allow using Modules.

I have been trying the following in my If-statement:
DCount("*", "subformName") = 0

However, I get the error that ms-access cannot analyse this.

Does anyone know where my mistake lies or a workaround?

Best,
Max
 
use macro If, and DCount on the Table or Query not on subform:

If DCount("1", "TheTable", "WhereConditionHere") = 0 Then
SetProperty [subformName]
Visible
False
 
Thanks, but unfortunately this still gives me the same error. It seems as if my MS-Access might not know DCount? However, according to https://support.microsoft.com/ the version (Professional Plus 2016) should have it.

I also tried other Tables, but nothing seems to work, also not outside of the If statement.

Is there an alternative to DCount I could try?
 
do you have Master/Child link fields on your subform?
 
Yes, I do. They both have "ID" in them, refering to the name the linking fields have in the two tables.
 
see this demo, open master form in design view and see the macro on "current" event.
 

Attachments

Thanks, I just figured it out - despite the official description of the German version of DCount stating to use commas between the inputs to the function, you actually have to use semicolons in the version I have... It's working now!
 

Users who are viewing this thread

Back
Top Bottom