Autowidth for columns in subForm

rockstar283

New member
Local time
Today, 05:27
Joined
Jul 10, 2014
Messages
5
I have developed an Access app, which has different navigational tabs which open up different forms. e.g. Tab A has Form A inside it and Form A has SubForm A1 inside it. For some reason, the following code is not working on any of the fields
Me.YourFieldName.ColumnWidth = -2

Can anyone please suggest me some workaround so that all the fields in the subforms will have auto width adjustable to fit in the text.
Thank you!!
 
I want to use the new code in OnClick event of the Navigation tab..so that everytime, the user clicks on the tab name, all the columns in the corresponding subforms will have proper width
 
columnwidth only applies to datasheets - is this the view you are using?

You also need to be much clearer in your problem and what you are doing

:confused:for example where is your code? main form, form A, form A1? What do you mean by navigation tab? A tab is a type of control but sounds like you are talking about a button.
 
to clarify more:

Got one Navigation Form NavFormA

NavFormA has different NavigationButtons. Button1 has FormB as its 'Navigation target name' i.e. it loads FormB when Button1 is clicked upon.

FormB has a subform subfrmC in it and subfrmC has datasheet in it.

I want to the columns of subfrmC to automatically adjust their widths whenever button1 is clicked.

NavFormA -> Button1 -> FormB -> subfrmC
 
suggest you do this in the form current event for subfrmc.

Code:
dim ctrl as Control
for each ctrl in me.Controls
    if ctrl.controltype = actextbox then ctrl.columnwidth=-2
next
 
suggest you do this in the form current event for subfrmc.

Code:
dim ctrl as Control
for each ctrl in me.Controls
    if ctrl.controltype = actextbox then ctrl.columnwidth=-2
next

Thanks mate..but its not working :banghead::banghead:

Here is my current code behind the subfrm

Private Sub Form_Current()


Dim ctrl As Control
For Each ctrl In Me.Controls
If ctrl.ControlType = acTextBox Then ctrl.ColumnWidth = -2
Next


End Sub


Private Sub Form_Load()


Me.txtClient.ColumnWidth = -2
Me.txtSDP.ColumnWidth = -2
Me.txtCategory.ColumnWidth = -2
Me.txtEmployee.ColumnWidth = -2
Me.txtTitle.ColumnWidth = -2
Me.txtManager.ColumnWidth = -2
Me.txtRollup.ColumnWidth = -2
Me.txtAllocation.ColumnWidth = -2
Me.txtOffice.ColumnWidth = -2


End Sub
 
can you define 'not working' - is the event occuring?

Also just to clarify you said
subfrmC has datasheet in it
I took this to mean that subfrmC is displayed as a datasheet - is this correct?
 
can you define 'not working' - is the event occuring?

Also just to clarify you said

I took this to mean that subfrmC is displayed as a datasheet - is this correct?

'Not Working' means the columns width is not getting automatically set in the form view.

You are Correct about the second part.
 
You only need to code once, suggest remove the code in the load event, then set a breakpoint to the if ctrl.controltype... line to make sure it is running

The current event is triggered every time you select a row so you can test the code by narrowing a column then clicking on another row.
 

Users who are viewing this thread

Back
Top Bottom