469,366 Members | 2,222 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,366 developers. It's quick & easy.

Hide labels and textboxes

I have a report in Access 2003. If I set the can shrink property on the textboxes they are invisible when they are empty, which is what I want. But it does not hide the associated label connected to it. Is that possible to do, either with vba or visual basic 6?
Thanks
Jan 20 '07 #1
12 41858
nico5038
3,080 Expert 2GB
Use for each field this code in the Detail's On Print event:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
  2. If Len(Nz(Me.YourField)) > 0 Then
  3.    Me.Label1.Visible = True
  4. Else
  5.    Me.Label1.Visible = False
  6. End If
  7. End Sub
This will hide (and free the space) the label.

Nic;o)
Jan 21 '07 #2
NeoPa
32,185 Expert Mod 16PB
I have a report in Access 2003. If I set the can shrink property on the textboxes they are invisible when they are empty, which is what I want. But it does not hide the associated label connected to it. Is that possible to do, either with vba or visual basic 6?
Thanks
To nick some of Nico's answer shamelessly (I wouldn't have thought of the Detail_Print event, but maybe the OnCurrent event would have worked as well) :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
  2.     Me!YourField.Visible = (Me!YourField>"")
  3. End Sub
I simply set the Visible property of the TextBox as this will handle both automatically assuming they're linked. The code is shorter but perhaps a little less obvious to the casual reader. The Visible property is set to the boolean value returned by the equation.
To be clear, this is an alternative, not a fix, to Nico's code, which will work fine for you.
Jan 22 '07 #3
I have a similar issue and used the code provided to hide the labels of the fields with no data. I have another question, is there a way to shrink the white space so the fields compact together--as it is, the fields are hidden, but it is like there is space reserved for the fields (they are just do not appear, but have enough space on the report to appear)...
Feb 13 '07 #4
Rabbit
12,516 Expert Mod 8TB
To shrink the white space you'd have to use code to either A) Move all controls over, expressed in twips or B) Set the X,Y coordinates for all the controls you want to move, expressed in twips.

For A, use:
Expand|Select|Wrap|Line Numbers
  1. Me.Control.Move Left, [Top], [Width], [Height]
For B, use:
Expand|Select|Wrap|Line Numbers
  1. Me.Control.Left = #
  2. Me.Control.Top = #
Feb 13 '07 #5
To shrink the white space you'd have to use code to either A) Move all controls over, expressed in twips or B) Set the X,Y coordinates for all the controls you want to move, expressed in twips.

For A, use:
Expand|Select|Wrap|Line Numbers
  1. Me.Control.Move Left, [Top], [Width], [Height]
For B, use:
Expand|Select|Wrap|Line Numbers
  1. Me.Control.Left = #
  2. Me.Control.Top = #
Sorry, this is all new to me, I will try the Me.Control.Move Left, [Top],[Width]...etc, but is the "Me" part the name of the label or field? and the "Top", "Width" is expressed in inches?
Feb 13 '07 #6
Rabbit
12,516 Expert Mod 8TB
Me is a reference to the form. Replace Control with the name of the control you want to move. Replace Left, Right, Height, Width with numbers expressed in twips (twip: Unit of measurement that is equal to 1/20 of a point, or 1/1,440 of an inch. There are 567 twips in a centimeter.)

So, if you have a text box named Foo and you need to move it 567 twips to the left, which is one centimeter, then you would use:
Expand|Select|Wrap|Line Numbers
  1. Me.Foo.Move -567
Top-Left is coordinate (0,0)
Feb 13 '07 #7
That makes sense...one last question, which section of the VB code does this go in, (Detail Print?)
Feb 13 '07 #8
Rabbit
12,516 Expert Mod 8TB
I'd put it in whichever Sub is hiding the labels.
Feb 13 '07 #9
Thanks, I will give it a try.
Feb 13 '07 #10
I'd put it in whichever Sub is hiding the labels.
Hi, I am trying to do the same thing as TinyTim but I am having problems. The invisible part works, but moving the text gives me an error. Here is what I have, can you tell me what I'm doing wrong?

Expand|Select|Wrap|Line Numbers
  1. If Len(Nz(Me.app)) > 0 Then
  2.  Me.app1.Visible = True
  3. Else
  4.  Me.app1.Visible = False
  5.  Me.app1.Move Top - 567
  6. End If
Apr 6 '07 #11
NeoPa
32,185 Expert Mod 16PB
Try :
Expand|Select|Wrap|Line Numbers
  1. If Len(Nz(Me.app)) > 0 Then
  2.  Me.app1.Visible = True
  3. Else
  4.  Me.app1.Move Top - 567
  5.  Me.app1.Visible = False
  6. End If
If this doesn't work, then post the question in a new thread.
This thread is not for your question.
Apr 10 '07 #12
NeoPa
32,185 Expert Mod 16PB
Another post was added to this thread but wasn't relevant so I've moved it to its own thread at How Do I Check Date Control is Filled.
Jan 18 '15 #13

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Dalan | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.