Resizing columns on a subform

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi - i am creating a contact management system as a hierarchical database and
have a company level screen and a tab with subforms below it showing all
divisions under that company and all contacts under that company. Im happy
to allow users to resize the columns on the subform if they are unable to
view all of the information but i cant get the columns to re-set to their
original size when i close and re-open the form - docmd.restore resets the
form to its original size but i am unable to get the columns themselves to do
so.

Any ideas?

Thanks,

Rhys
 
This code sets all columns to the Access default width (that's what the -1
in the code does) ...

Private Sub Form_Load()

Dim frm As Form
Dim ctl As Control

Set frm = Me.sfrTest.Form
For Each ctl In frm.Controls
If ctl.ControlType = acTextBox Then
ctl.ColumnWidth = -1
End If
Next ctl

End Sub

If you want to re-set the controls to your design-time width, you could
hard-code the names and widths, or more flexibly, store them somewhere, for
example in a table, and retrieve them at run time.
 
Hi Brendan - i posted this and then went on holiday for 2 weeks!
Im not sure i exactly understand how the code works - what parts of the code
do i need to substitute with my form name etc?

Thanks,

Rhys.
 
Hi Brendan - sorry sat down properly and had a look at it and modified the
code and it now works fine so thanks a lot for that!
 
yeah it works a treat , the only thing i did change was

Set frm = Me.sfrTest.Form

to Set frm = Me!

otherwise it didnt work
 
In my example, the code was in the Load event procedure of the main form, so
'Set frm = Me.sfrTest.Form' was getting a reference to the form contained in
the subform control. If your code is behind the subform, rather than the
main form, then you would use 'Set frm = Me' to get a reference to that
form. Note 'Me' not 'Me!' there should be no exclamation point there.
 
Back
Top