Connecting Tech Pros Worldwide Forums | Help | Site Map

Access Report: Hiding field and Label when field is null

Member
 
Join Date: Nov 2008
Posts: 47
#1: Jun 15 '09
Hi all:

On Access 2003: I have a tabular form with labels next to the associated fields. I'd like them both to dissappear when the associated field is null. ("Can Shrink" will do this for the field, but the label is still there, so the report does not shrink.)

Any ideas how I can make the label shrink too?

Thanks,

Expert
 
Join Date: Jul 2008
Location: Maryland
Posts: 1,176
#2: Jun 16 '09

re: Access Report: Hiding field and Label when field is null


Simply change the label to a text box with no backcolor, and set conditional formatting so that if the value is null ( or [control] = "" ), the text is the same color as the background. You will want to lock and disable the text box so the text can't be selected when it is not supposed to be visible.
Member
 
Join Date: Nov 2008
Posts: 47
#3: Jun 16 '09

re: Access Report: Hiding field and Label when field is null


Thanks.

Actually, I found a different answer: I changed the label to a text box and set the control source to iif(isnull([related control]),null,"Label Title"). Then I set the Can Shrink properties for the label and the related to control to Yes.
Expert
 
Join Date: Jul 2008
Location: Maryland
Posts: 1,176
#4: Jun 16 '09

re: Access Report: Hiding field and Label when field is null


Thank you for sharing your solution. That's probably a much better idea, since I've experienced slow updating with conditional formatting.
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,747
#5: Jun 17 '09

re: Access Report: Hiding field and Label when field is null


Each section in a report has a Format event. You could handle this without any special usages of controls simply by setting the .Visible property of both controls to (Not IsNull(Me.Control)).
Expert
 
Join Date: Jul 2008
Location: Maryland
Posts: 1,176
#6: Jun 17 '09

re: Access Report: Hiding field and Label when field is null


Ah, I was thinking of continuous forms. Would the Format event work in that case? Forgive my laziness in not trying it myself, but I think it's quicker to ask.
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,747
#7: Jun 17 '09

re: Access Report: Hiding field and Label when field is null


Quote:

Originally Posted by ChipR View Post

Forgive my laziness in not trying it myself, but I think it's quicker to ask.

Not at all. Happy to answer.

I believe the Format event is specific to Report sections and is not available anywhere I can find for forms.
Member
 
Join Date: Nov 2008
Posts: 47
#8: Jun 17 '09

re: Access Report: Hiding field and Label when field is null


NeoPa,

I admit I'm baffled. (I'm only a programmer by circumstance, not by training.) Note, I'm using Access 2003.

1: What's the "Format event". Is that the format tab in the properties of the form?
2: I can't put that code in dialog box for Is Visible -- it limits me to Yes and No

Can you explain? Thanks.
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,747
#9: Jun 17 '09

re: Access Report: Hiding field and Label when field is null


I will be happy to. Unfortunately, I will need to be careful to explain it in terms that make sense to you which will take time I don't have immediately available.

If you see nothing by tomorrow bump the thread and I'll post a proper explanation.
Member
 
Join Date: Nov 2008
Posts: 47
#10: Jun 17 '09

re: Access Report: Hiding field and Label when field is null


NeoPa,

Thanks for the offer, but it's not necessary; I have a solution that works. But if you're willing to give me 3 or 4 minutes, (and no more) I'd like to understand where to put the code you suggest -- do I go into code builder and build a sub called control_format(...); if so, is it attached to the control or to the form definition?


Thanks,


Dante
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,747
#11: Jun 18 '09

re: Access Report: Hiding field and Label when field is null


OK. Here goes. A little intro to programming in VBA and the structures you can work with.

Most code in VBA is instigated by events. There are various objects (such as forms; reports; controls on either forms or reports; etc; etc). Typically objects have various events associated with them. An event can be considered as a trigger for starting specific relevant code - generally termed an Event Handler Procedure.

I won't go into too much detail of all the possible events for all the possible objects as they are really far too numerous to mention. To put this in context though, a report has various sections, each of which has a Format event associated with them. Forms don't have any objects with a Format event as far as I'm aware, so this should be considered exclusively for reports.

When assigning code to an event, what you need to do is the following (to start you off right) :
  1. Open the containing object in Design Mode (if the object is a form or report then it won't be contained).
  2. Select the object (control; section; etc).
  3. Show Properties and select the Event from the list.
  4. The value will have a drop-down and the value "[Event Procedure]" will be available. Select this and click on the ellipsis button to the right.
  5. This will switch to the IDE (Integrated Development Environment) and create a procedure shell for you to populate with your code.
Member
 
Join Date: Nov 2008
Posts: 47
#12: Jun 18 '09

re: Access Report: Hiding field and Label when field is null


Thank you NeoPa. You helped me find the one piece of the puzzle that I was missing. I'd been looking for the events associated with the controls, or at the form level, but not at the detail section level. Now I see the "on Format" event.

Thanks again.


Dante
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,747
#13: Jun 18 '09

re: Access Report: Hiding field and Label when field is null


Pleased to help Dante, though still a little curious that you refer only to Forms when talking about the Format event. You do appreciate that this is fundamentally Report related rather than anything to do with Forms as such?
Member
 
Join Date: Nov 2008
Posts: 47
#14: Jun 18 '09

re: Access Report: Hiding field and Label when field is null


My mistake; I meant reports.

Thanks again
Reply

Tags
can shrink, null fields, report