Fill Subform Width After Form Is Anchored

speakers_86

Registered User.
Local time
Today, 03:39
Joined
May 17, 2007
Messages
1,919
I have a datasheet subform anchored to the bottom right. I want the columns in it to stretch across the whole subform. Am I able to do this? The line that is printed is:

8580 8579

but there is still plenty of room left in the subform.

Code:
Private Sub Form_Load()
    Me.MissionID.ColumnHidden = True
    Me.TerminalID.ColumnHidden = True
    Me.txtView.ColumnWidth = -2
    Me.Search.ColumnWidth = -2
    Dim lngW As Long
    lngW = Me.Parent.frmShiftBriefMissions.Width
    Me.FriendlyName.ColumnWidth = 0.4 * (lngW - Me.txtView.ColumnWidth - Me.Search.ColumnWidth)
    Me.Terminal.ColumnWidth = 0.2 * (lngW - Me.txtView.ColumnWidth - Me.Search.ColumnWidth)
    Me.cboRx.ColumnWidth = 0.2 * (lngW - Me.txtView.ColumnWidth - Me.Search.ColumnWidth)
    Me.cboTx.ColumnWidth = 0.2 * (lngW - Me.txtView.ColumnWidth - Me.Search.ColumnWidth)

    Debug.Print lngW & " " & Me.txtView.ColumnWidth + Me.Search.ColumnWidth + Me.FriendlyName.ColumnWidth + Me.Terminal.ColumnWidth + Me.cboRx.ColumnWidth + Me.cboTx.ColumnWidth

    'AutoWidth Me
End Sub
 
Code:
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' arnel g. puzon (arnelgp)
' 27-Aug-2015
'
' Resize columns in datasheet
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub Form_Load()
    Dim lngW As Long
    With Me
        ' reset all column size to default value before adjusting
        !txtView.ColumnWidth = 1500
        !Search.ColumnWidth = 1500
        !FriendlyName.ColumnWidth = 1500
        !Terminal.ColumnWidth = 1500
        !CboRx.ColumnWidth = 1500
        !CboTx.ColumnWidth = 1500
        
        ' hide 2 columns
        !MissionID.ColumnHidden = True
        !TerminalID.ColumnHidden = True
        
        ' autofit 2 columns
        !txtView.ColumnWidth = -2
        !Search.ColumnWidth = -2
        
        ' actual window width is InsideWidth
        ' deduct the left side width (what do you call it?) 270
        ' and the Horizontal scroll bar width 270
        lngW = .InsideWidth - (270 * 2)
        
        ' deduct the width of the 2 autofit columns
        lngW = lngW - !txtView.ColumnWidth - !Search.ColumnWidth
        
        ' now adjust the columns
        !FriendlyName.ColumnWidth = 0.4 * lngW
        !Terminal.ColumnWidth = 0.2 * lngW
        !CboRx.ColumnWidth = 0.2 * lngW
        !CboTx.ColumnWidth = 0.2 * lngW
    End With
End Sub
 
The inside width is 8568, which is slightly smaller than using the width of the subform control, so the result is about the same. I think the issue is that I can't tell the size of the subform once the anchoring is applied.

edit- I think I got it now. Using inside width on the resize event seems to have done it. Thanks.

edit-I'm having issues with reliability. I think setting the column width to -2 is asynchronous, and if that routine is not finished yet, the rest of the code is wrong. Explicitly setting the width seems to be working.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom