.visible (1 Viewer)

pekajo

Registered User.
Local time
Today, 14:01
Joined
Jul 25, 2011
Messages
133
Hi ,
I am using the following code in the Detail of a report.

Reports!R_PreCard![PName].Visible = (Reports!R_PreCard![PSurname] <> "a")

but am getting popup message:
'Object doesn't support this Property or Method.'

Can anyone help as to why?
Thanks
Peter
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 21:01
Joined
Oct 29, 2018
Messages
21,581
Which event are you using?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 23:01
Joined
Feb 28, 2001
Messages
27,388
That addressing method should work with the Me prefix, such as

Me.PName.Visible = Me.PSurname <> "a"

If that fails, then the next question would be what is the nature of PName? IF that is the name of both a control and a field then change the name of the control and refer to it by the altered name. It is possible to see not only the controls of a report but also the fields of the underlying query when in "Me." context, so it is POSSIBLE (not going to swear to it) that Access is confused about which PName you meant. If it is confused, the Pname that is the field name doesn't have a .Visible property.
 

pekajo

Registered User.
Local time
Today, 14:01
Joined
Jul 25, 2011
Messages
133
That addressing method should work with the Me prefix, such as

Me.PName.Visible = Me.PSurname <> "a"

If that fails, then the next question would be what is the nature of PName? IF that is the name of both a control and a field then change the name of the control and refer to it by the altered name. It is possible to see not only the controls of a report but also the fields of the underlying query when in "Me." context, so it is POSSIBLE (not going to swear to it) that Access is confused about which PName you meant. If it is confused, the Pname that is the field name doesn't have a .Visible property.
Now getting the message
1648007584873.png
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 00:01
Joined
May 21, 2018
Messages
8,651
Did you do what @The_Doc_Man said. The name of the control is not always the name of the field. So the field PName my be in control Text1. A field does not have a visible property per your error message. You need to rename the control or change the code to use the controls real name.
 

LarryE

Active member
Local time
Yesterday, 21:01
Joined
Aug 18, 2021
Messages
612
Hi ,
I am using the following code in the Detail of a report.

Reports!R_PreCard![PName].Visible = (Reports!R_PreCard![PSurname] <> "a")

but am getting popup message:
'Object doesn't support this Property or Method.'

Can anyone help as to why?
Thanks
Peter
  1. The .Visible property can only be set to True or False, so your VBA statement makes no sense. ACCESS cannot process it.
  2. You didn't state what you are attempting to achieve, so we can't know how to help you. Please tell us what your goal is. Are you attempting to set the visibility property of a field when the report opens? Are you attempting to set the visibility property if a specific condition occurs?
 

GPGeorge

George Hepworth
Local time
Yesterday, 21:01
Joined
Nov 25, 2004
Messages
2,048
  1. The .Visible property can only be set to True or False, so your VBA statement makes no sense. ACCESS cannot process it.
  2. You didn't state what you are attempting to achieve, so we can't know how to help you. Please tell us what your goal is. Are you attempting to set the visibility property of a field when the report opens? Are you attempting to set the visibility property if a specific condition occurs?
Actually, the line of code includes this evaluation, which DOES return true or false:

(Reports!R_PreCard![PSurname] <> "a")

If the PSurname is "a", then that expression evaluates to false. If the PSurname is NOT "a", then the expression evaluates to true.

However, that's possibly the wrong expression, since not many people in the world have, as their surname, a single letter "a".

Or maybe the PSurname is always single letters? In addition to the problem of control vs field reference, one has to know what the actual data in the field is.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 05:01
Joined
Sep 12, 2006
Messages
15,728
it might need to be the onformat() or onprint() event.

when you get it working, you might want an nz() round the surname field you are testing.
 

LarryE

Active member
Local time
Yesterday, 21:01
Joined
Aug 18, 2021
Messages
612
Actually, the line of code includes this evaluation, which DOES return true or false:

(Reports!R_PreCard![PSurname] <> "a")

If the PSurname is "a", then that expression evaluates to false. If the PSurname is NOT "a", then the expression evaluates to true.

However, that's possibly the wrong expression, since not many people in the world have, as their surname, a single letter "a".

Or maybe the PSurname is always single letters? In addition to the problem of control vs field reference, one has to know what the actual data in the field is.
I had no idea you could set a field property like this.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 00:01
Joined
Feb 19, 2002
Messages
43,592
It is a "clever" but obtuse shortcut for an If-then-else statement which everyone would understand.

@pekajo Did you verify that you are using the Control Name rather than the name of the bound field when setting the .visible property?

If the wizard made the form, it names the control after the name of the bound column so there wouldn't be any difference. If you made the form, there could very easily be a difference if you were not conscious about properly naming the controls. Or, if you are old school, like I am, you deliberately give the control a name different from the bound column. This method allows me to be specific. When I refer to properties of the control I use the control name.
Me.txtSomeName.Visible = True
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 14:01
Joined
Jan 20, 2009
Messages
12,863
Or, if you are old school, like I am, you deliberately give the control a name different from the bound column. This method allows me to be specific. When I refer to properties of the control I use the control name.
The control is the default and renaming them a waste of time because you will get the control every time if there is one by the name.
If you want to refer to the field instead, just use its full reference. Can't get any more explicit than that.
Code:
Me.Recordset.somename

The full reference to the control is
Code:
Me.Controls.somename
 

pekajo

Registered User.
Local time
Today, 14:01
Joined
Jul 25, 2011
Messages
133
Hi,
Thanks for all the helpful advice.
I should explain what I am trying to achieve as there maybe a better way.
I am printing business card labels. There are 10 business cards to a page. If I have used the first 3 labels I want to start the labels at position 4 on the used sheet.
So I add 3 rows with 'a' in the PName field and sort on the PName field so they are the first in the sort. At this point I have the labels starting to print at position 4. Then I 'hide' the fields in the first 3 labels with this code so they do not print any fields/data etc.
Hope that explains the reason for the code.
If there is a better way would like to hear from you.
Peter
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 00:01
Joined
Feb 19, 2002
Messages
43,592
You cleverly avoided answering the question of the control name vs the field name. It is only if they are different that you need to know which is which and use the control name when you are referring to properties of the control.

But now that we know what you are doing, just don't put values in the columns. Just add empty rows to the query. That way you can "print" the empty labels without worry. You don't need any code to hide controls so it doesn't matter at all if the control name is different from the field name.
 

Users who are viewing this thread

Top Bottom