Insert subform based on formula

I want to hide a section of a form, I have placed it on subform and did the insert subform based on formula, but my formula doesn’t work, as it is not displaying the subform when necessary.

I want it to display only if the User who opens the document is the CreatedBy person or the Manager selected or has the role [Admin]. I have even created a field Valid Names with the formula: “[Admin]” : @Name([Abbreviate];CreatedBy): @Name([Abbreviate];Manager)

and then I set the formula on the Subform as →

Tmp:=@Name([Abbreviate];@UserName);

@If(@Contains(ValidNames;Tmp);“HiddenSubform”;“”)

I have also tried @IsMember, but no luck. Even if I save and exit the form and reopen.

Any ideas?

Subject: RE: Insert subform based on formula

You have to think about what the value of the ValidNames field, and the other fields, is at the time you execute the subform formula, which is while loading the form. Field formulas are executed in order from top to bottom and left to right, and the subform formula executed when you come to it. The decision which subform to display is made at that time and doesn’t change while the form is open.
Why, when you have a canonical name, and another canonical name, do you abbreviate them both before comparing them? Just compare them; it’s faster.

@Contains is the wrong function; use *=, e.g.

@If(@UserNamesList *= “[Admin]” : CreatedBy: Manager; “HiddenSubform”; “”)

Note that nobody’s username is “[Admin]”, so that will never match if you just compare with the username.

Subject: Insert subform based on formula

Of course your role will never trigger since this is not a username.

Correct code should be

tmp := @if(@Ismember([Admin];@Userroles)| @Name([Abbreviate];@Username) = @Name([Abbreviate];CreatedBy): @Name([Abbreviate];Manager);@True;@False);

@If(tmp;“HiddenSubform”;“”);

This of course assumes that the names in the CreatedBy and Manager field are in a format that can be converted to Abbreviated version and that there is a single value in those fields.

Subject: RE: Insert subform based on formula

Marjan, you rock!

I had put this in, and it works 100%. Thank you! I had to put [Admin] between “” though, but now it works. Thanks again.

tmp := @If(@IsMember(“[Admin]”;@UserRoles)| @Name([Abbreviate];@UserName) = @Name([Abbreviate];CreatedBy): @Name([Abbreviate];Manager);@True;@False);

@If(tmp;“HiddenSubform”;“”)

Subject: RE: Insert subform based on formula

Thank you, I will try it out, the field Valid Names are actually after the computed subform, so I have moved it to the top. Will let you know what worked.

Thanks again!