Wrapping Text in a combobox dropdown menu (1 Viewer)

BJF

Registered User.
Local time
Today, 02:07
Joined
Feb 19, 2010
Messages
133
Hello,

Does anyone know how to wrap text in a combobox dropdown?

I set the combobox "can grow" property to YES but it still wont wrap text on items longer than the specified column width.

Any suggestions would be much appreciated.
Thanks,
BJF
 

June7

AWF VIP
Local time
Yesterday, 22:07
Joined
Mar 9, 2014
Messages
5,424
Can't be done with intrinsic combobox control. Not aware of any add-in that can.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 23:07
Joined
Oct 29, 2018
Messages
21,358
As @June7 mentioned, it's not a built-in functionality. You might create your own word wrap function and run your row source data through that for your combobox. Just a thought...
 

BJF

Registered User.
Local time
Today, 02:07
Joined
Feb 19, 2010
Messages
133
ok, thank you for the responses, i will check into DBguys suggestion. Im not familiar with writing functions but ill try.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 23:07
Joined
Oct 29, 2018
Messages
21,358
ok, thank you for the responses, i will check into DBguys suggestion. Im not familiar with writing functions but ill try.
Yes, give it a shot and post back if you get stuck. Good luck!
 

June7

AWF VIP
Local time
Yesterday, 22:07
Joined
Mar 9, 2014
Messages
5,424
Could have a textbox that references the combobox column. Textbox can wrap and provides a scroll bar. No VBA needed.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 02:07
Joined
May 21, 2018
Messages
8,463
Can you give an example of the types of values and the combobox width? Are these sentences and you want them to wrap on words or can they split anywhere?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 02:07
Joined
May 21, 2018
Messages
8,463
You might create your own word wrap function and run your row source data through that for your combobox. Just a thought...
I do not think that would work. The height of each row is set. If you forced carriage returns into the string that is not going to do anything. Maybe I am not seeing it. I think you are going to want to have a "zoom" box on the side to see the full text.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 23:07
Joined
Oct 29, 2018
Messages
21,358
I do not think that would work. The height of each row is set. If you forced carriage returns into the string that is not going to do anything. Maybe I am not seeing it. I think you are going to want to have a "zoom" box on the side to see the full text.
Thanks for that insight. I hadn't considered it. Cheers!
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 02:07
Joined
May 21, 2018
Messages
8,463
If you want to fake this, I think this is a pretty good fake and pretty reuseable code.
Wrapped Combo.png


That is a combobox and a subform. The subform is made visible when you try to select from the combo. To reuse it build a data sheet subform with your field to display. Call that field txtSelection. Do not worry about the properties of the subform because those are set in code.

Add this code to the subform
Code:
Public Event Selected(Selection As Variant)
Private Sub txtSelection_Click()
  RaiseEvent Selected(Me.txtSelection)
End Sub
You can pass back any value so more likely it is a Primary key from another control

Put this in a module
Code:
Public Sub FormatFakeCombo(cmbo As Access.ComboBox, subfrm As Access.SubForm)
  cmbo.SetFocus
  With subfrm
   .Left = cmbo.Left
  .Height = 0
  .Visible = False
  .Width = cmbo.Width
  End With
  With subfrm.Form
    .NavigationButtons = False
    .AllowAdditions = False
    .AllowEdits = False
    .AllowDeletions = False
    .RecordSelectors = False
    'need to call the textbox txtselection
    .txtSelection.ColumnWidth = subfrm.Width - 500
   End With
End Sub
Public Sub ExpandFakeCombo(subfrm As Access.SubForm, height_Inches As Long)
  subfrm.Visible = True
  subfrm.Height = height_Inches * 1440
End Sub
Public Sub CollapseFakeCombo(cmbo As Access.ComboBox, subfrm As Access.SubForm)
  cmbo.SetFocus
  subfrm.Height = 0
  subfrm.Visible = False
End Sub
Public Function IsExpanded(subfrm As Access.SubForm) As Boolean
  IsExpanded = (subfrm.Height > 0)
End Function

Then in the main form something like
Code:
Option Compare Database
Option Explicit
'Needed to capture the after update of the subfrm
Private WithEvents FakeSelection As Form_subFrmFakeCombo
Private Sub cmboLong_KeyDown(KeyCode As Integer, Shift As Integer)
  ExpandFakeCombo Me.SubfrmFakeCombo, 4
End Sub
Private Sub cmboLong_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
   If IsExpanded(Me.SubfrmFakeCombo) Then
     CollapseFakeCombo Me.cmboLong, Me.SubfrmFakeCombo
   Else
     ExpandFakeCombo Me.SubfrmFakeCombo, 4
   End If
End Sub
Private Sub Form_Current()
  FormatFakeCombo Me.cmboLong, Me.SubfrmFakeCombo
  Set FakeSelection = Me.SubfrmFakeCombo.Form
End Sub
Private Sub FakeSelection_Selected(Selection As Variant)
  Me.cmboLong = Selection
  CollapseFakeCombo Me.cmboLong, Me.SubfrmFakeCombo
End Sub
 

Attachments

  • FakeWrapCombo.accdb
    4.1 MB · Views: 306

Users who are viewing this thread

Top Bottom