Programmatically changing form header height - problems

J

Julia B

Hi all

I've got a continuous form with some hidden fields in the header, which are
made visible during certain circumstances. The fields take up quite a bit of
space and when invisible I would like to reduce the size of the header so it
looks like there's not a lot of blank empty space.

I've tried adjusting the formheader.height property, but this only seems to
work if I make it bigger, it just won't go smaller than required to show all
the invisible fields.

Is there a way to get rount this?

Thanks for your help in advance.
Julia
 
P

Peter Hibbs

Julia,

Before you change the height of the FormHeader section you would need
also to change the height of any invisible controls. You could set
their height to 1 Twip (since they are not visible anyway) and when
you re-display the header section you would need to change the height
of those controls back to what they were before you make them visible
again.

If you have the Record Selectors visible on a Continuous form, you
will need to do a Me.Requery after you resize the FormHeader,
otherwise they will be in the wrong position.

HTH

Peter Hibbs.
 
J

Julia B

Hi Peter, that makes sense thanks. However, there are a lot of controls and I
hide/unhide them with some subs as follows:

Private Sub HideEditControls()
'this sub hides all the edit controls in the form header, each of which
has a tag
Me.FinalImportRef.SetFocus
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Tag = "EditGroup" Then
ctl.Visible = False
End If
Next
End Sub

Private Sub UnhideEditControls()
'this sub unhides all the edit controls in the form header, each of
which has a tag
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Tag = "EditGroup" Then
ctl.Visible = True
End If
Next
End Sub

So in theory I should be doing ctl.Height = 1 etc but ctl does not have a
height attribute. It has a Properties atttribute and I've tried:

ctl.Properties("Height") = 1 but this does not work.

Have you any further suggestions?
Thanks
Julia
 
P

Peter Hibbs

Julia,

Your theory is correct, you just needed to follow it through.

This code should work :-

For Each ctl In Me.Controls
If ctl.Tag = "EditGroup" Then
ctl.Visible = False
ctl.Height = 1
End If
Next

I know that when you type in ctl. the VBA editor does not show .Height
as an option but it still works. I guess this is because the variable,
ctl, is not a proper control, it is a pseudo control. Anyway, try that
first and see what happens.

However, there are a few other issues with your set up that you may
need to consider :-

1. If your Text box controls have attached labels then you need to
resize those as well. Just set the Tag property of any labels to
'EditGroup' (which you may have done already).

2. If all the hidden controls have the same height then you can add
the same line of code in the UnhideEditControls routine to restore
them with ctl.Height = 250 (or whatever the value is). If you have
controls with different heights, then restoring them is slightly more
complicated (but I have an idea on that, if needed).

3. If the Top position of any of the controls is lower than than the
bottom edge of the FormHeader section after you have resized it, then
you will also need to move those controls to the top of the FormHeader
section (and then move them back again when you re-display the
header). This will complicate things a bit more but it can be done.

Anyway, try the above first and let us know how you get on.

Peter Hibbs.
 
J

Julia B

Thanks Peter, I will need to move the controls before making them invisible
which is going to be a pain but I can see how to do it.

Thanks for your time.
Julia
 
S

Stuart McCall

Julia B said:
Thanks Peter, I will need to move the controls before making them
invisible
which is going to be a pain but I can see how to do it.
<snip>

The reason it's going to be a pain is because they'll be difficult to select
in future? The answer is to select them via the drop-down at the top of the
property page.

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top