Count records in subform (1 Viewer)

maxgold

New member
Local time
Today, 01:17
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
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 07:17
Joined
May 7, 2009
Messages
19,227
use macro If, and DCount on the Table or Query not on subform:

If DCount("1", "TheTable", "WhereConditionHere") = 0 Then
SetProperty [subformName]
Visible
False
 

maxgold

New member
Local time
Today, 01:17
Joined
Jan 28, 2022
Messages
20
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?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 07:17
Joined
May 7, 2009
Messages
19,227
do you have Master/Child link fields on your subform?
 

maxgold

New member
Local time
Today, 01:17
Joined
Jan 28, 2022
Messages
20
Yes, I do. They both have "ID" in them, refering to the name the linking fields have in the two tables.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 07:17
Joined
May 7, 2009
Messages
19,227
see this demo, open master form in design view and see the macro on "current" event.
 

Attachments

  • linkedByID.accdb
    644 KB · Views: 188

maxgold

New member
Local time
Today, 01:17
Joined
Jan 28, 2022
Messages
20
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

Top Bottom