Results 1 to 11 of 11

Thread: autoexpand column values not save in access 2016

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #8
    VBAX Contributor
    Joined
    Nov 2020
    Location
    Swansea,South Wales,UK
    Posts
    126
    Location
    Here is what I use for a combo in a subform of mine.
    Private Sub cboFoodIDFK_GotFocus()
        ' Debug.Print Me.cboFoodIDFK.ColumnWidths
        Me.cboFoodIDFK.Dropdown
        TempVars("FoodWidth").Value = Me.cboFoodIDFK.Width
        ' Debug.Print "GotFocus " & TempVars("FoodWidth").Value
        Me.cboFoodIDFK.Width = "8000"
        Me.cboFoodIDFK.ColumnWidths = ExpandCombo(Me.cboFoodIDFK.ColumnWidths)
    End Sub
    
    
    Private Sub cboFoodIDFK_LostFocus()
        ' Debug.Print "LostFocus " & TempVars("FoodWidth").Value
        Me.cboFoodIDFK.Width = TempVars("FoodWidth").Value
        Me.cboFoodIDFK.ColumnWidths = ShrinkCombo(Me.cboFoodIDFK.ColumnWidths)
    End Sub
    
    Public Function ExpandCombo(pstrWidths As String) As String
        Dim strWidth() As String, strNewWidth As String
        Dim i As Integer
        strWidth() = Split(pstrWidths, ";")
        ' For i = 0 To UBound(strWidth)
        ' Debug.Print strWidth(i)
        ' Next
        strWidth(1) = CStr(Val(strWidth(1)) * 1.5)
        For i = 0 To UBound(strWidth)
             strNewWidth = strNewWidth & strWidth(i) & ";"
             ' Debug.Print strWidth(i)
        Next
        ' Debug.Print strNewWidth
        ExpandCombo = Left(strNewWidth, Len(strNewWidth) - 1)
        ' Debug.Print "Expanding " & ExpandCombo
        'MsgBox ExpandCombo
    End Function
    
    
    Public Function ShrinkCombo(pstrWidths As String) As String
        Dim strWidth() As String, strNewWidth As String
        Dim i As Integer
        strWidth() = Split(pstrWidths, ";")
        ' For i = 0 To UBound(strWidth)
            ' Debug.Print strWidth(i)
        ' Next
        strWidth(1) = CStr(Val(strWidth(1)) / 1.5)
        For i = 0 To UBound(strWidth)
             strNewWidth = strNewWidth & strWidth(i) & ";"
             ' Debug.Print strWidth(i)
        Next
        ShrinkCombo = Left(strNewWidth, Len(strNewWidth) - 1)
        ' Debug.Print "Shrinking " & ShrinkCombo
        ' MsgBox ShrinkCombo
    End Function
    Last edited by Aussiebear; 01-04-2025 at 02:14 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •