Full Version: Size to fit - columns in subform
UtterAccess Forums > Microsoft® Access > Access Forms
carlclifford
Does anyone know the vba equivalent of double clicking the border of a column in a subform. I have a subform in datasheet view (I would like to keep it in datasheet view) and I would like to automate the resizing of the columns whenever the user selects new data in the parent form.
I have been trying to reset the width of the controls to -2 but I get a "control or subform control is too large for this location" error.
Thanks
Carl
mhourie
CODE
Private Sub Form_Current()
'This will resize the columns to the exact length of the data
With Me
    .txtJob.ColumnWidth = -2
End With
End Sub

HTH
Michael
carlclifford
Thanks but I am still getting the Run-Time error 2100 control or subform control too large for this location.
carlclifford
I should probably mention that the subform is on a tab control in case that is relevant
mhourie
Did you place the Form_Current event inside the subform or Parent? Also, you mention when a user selects new data. Try placing it in the after update event of the control the user is using to select new data? Somewhere after a Me.Requery?

Having a subform on a tab control is OK. Check out mvps.org if you are ever unsure of how to reference parent and child forms.
Edited by: mhourie on Mon Nov 22 15:14:14 EST 2004.
carlclifford
Definitely in the subform. Still getting the run-time 2100 no matter where i put it.
mhourie
I am sorry but I do not know what that error is. Here is my exact code from Access 2000 and it works for me. I put it in the On Current event of my subform that is linked to my mainform.
CODE
Private Sub Form_Current()
With Me
    .txtUtility.ColumnWidth = 850
    .txtJob.ColumnWidth = -2
    .txtProject.ColumnWidth = -2
    .txtDescription.ColumnWidth = 2000
    .txtTargetDate.ColumnWidth = -2
    .txtContract.ColumnWidth = 1250
    .txtBalance.ColumnWidth = -2
    .cxbContingent.ColumnWidth = 850
    .txtDepositAmt.ColumnWidth = -2
End With
And Sub
carlclifford
not exactly a quick reply but this did work finally - thanks!
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.