Textbox can act like "Combo Box"

smtazulislam

Member
Local time
Today, 20:14
Joined
Mar 27, 2020
Messages
808
Hi, see attached.
I want to combo box in a form, but I do not want to display the drop down arrow. It is just display 6 Or 8 Rows when user click in the textbox.
Is it possible ?

Note : Display picture in aspx.net work...
 

Attachments

  • Untitled.png
    Untitled.png
    11.7 KB · Views: 101
No,that’s why they invented Combo box.
 
Only thing I could think of is to overlay a Textbox on top of the Combobox.
 
I deleted my answer as I was answering the wrong question!!!
 
on the demo click on City2, and Use Alt-Down key to show the combo list.
you can simulate this on OnGotFocus event of City2 using Sendkeys:

Private sub City2_OnGotFocus()
Sendkeys "%{DOWN}"
end sub
 

Attachments

on the demo click on City2, and Use Alt-Down key to show the combo list.
you can simulate this on OnGotFocus event of City2 using Sendkeys:

Private sub City2_OnGotFocus()
Sendkeys "%{DOWN}"
end sub
Thank you very much. But it is not work in my computer...
 
did you try to press ALT+DOWN (arrow) on City2?
 
The problem with not opening the drop down is that a user cannot select between similar options within the list. He will automatically get the first matching option, which is what happens if you just type into the unopened combo box.
 
Glowbox.PNG
put on focus of txtRecipient me.cmdRecipient.borderstyle = 1
and me.subform.visible = true the listbox is not a listbox but a subform with shade effect.
 
View attachment 103067put on focus of txtRecipient me.cmdRecipient.borderstyle = 1
and me.subform.visible = true the listbox is not a listbox but a subform with shade effect.
I dont want to Shade or effect. Its optional work.
I just want to work when I click the textbox then act same like combo box drop down list. Maybe it is 6 rows or 8 rows display.
 
Here is a 95% solution and provides some nice features.
1. The size of the list can be customized.
2. You can display the visible column of the list but store the key or another field.
3. you can scroll up and down using the arrow keys and select with enter
4. you can select with the mouse
5. Takes a couple lines of code to make this

Form code.
Code:
Public ListExpand As ExpandableListbox
Private Sub Form_Load()
  Set ListExpand = New ExpandableListbox
  ListExpand.Initialize Me.txtExpand, Me.lstExpand, 1.25, True
End Sub

You need to add a textbox and a listbox on a form. The listbox can be dropped wherever, it will be moved and resized
Need to add the class module to your project.

Code:
Option Compare Database
Option Explicit

Private WithEvents mTextBox As Access.TextBox
Private WithEvents mListBox As Access.ListBox
Private mHeightPixels As Integer
Private mUpdateTextBox As Boolean
Private mVisibleColumn As Integer
Private WithEvents mForm As Access.Form

Public Sub Initialize(TheTextBox As Access.TextBox, TheListBox As Access.ListBox, Optional HeightInInches = 1, Optional UpdateTextBox As Boolean = True)
  Set mTextBox = TheTextBox
  Set mListBox = TheListBox
  mHeightPixels = HeightInInches * 1440
  With mTextBox
    .OnMouseDown = "[Event Procedure]"
    .OnKeyDown = "[Event Procedure]"
    .OnMouseUp = "[Event Procedure]"
    .OnKeyUp = "[Event Procedure]"
    .Locked = True
  End With
  With mListBox
    .Left = mTextBox.Left
    .Height = 0
    .Top = mTextBox.Top + mTextBox.Height
    .Width = mTextBox.Width
    .AfterUpdate = "[Event Procedure]"
    .OnMouseDown = "[Event Procedure]"
    .OnKeyDown = "[Event Procedure]"
    .OnClick = "[Event Procedure]"
  End With
  Set mForm = TheTextBox.Parent
  mForm.OnCurrent = "[Event Procedure]"
  mUpdateTextBox = UpdateTextBox
  SetVisibleColumn
End Sub
Private Sub SetVisibleColumn()
  Dim aWidths() As String
  Dim i As Integer
  If mListBox.ColumnCount > 0 And mListBox.ColumnWidths <> "" Then
      aWidths = Split(mListBox.ColumnWidths, ";")
      For i = 0 To UBound(aWidths)
        If aWidths(i) <> "0" Then
          mVisibleColumn = i
          Exit For
         End If
      Next i
    End If
End Sub

Private Sub mForm_Current()
  mListBox.Visible = False
End Sub

Private Sub mForm_Load()

End Sub

Private Sub mListBox_AfterUpdate()
   If mUpdateTextBox Then mTextBox.Value = mListBox.Column(mVisibleColumn)
  'ShrinkList
End Sub
Private Sub mListBox_KeyDown(KeyCode As Integer, Shift As Integer)
  If KeyCode = 13 Then
     mTextBox.SetFocus
     ShrinkList
  End If
  'Causes some random value to get selected
End Sub

Private Sub mListBox_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  ShrinkList
  'For some reason causes the value to not select
End Sub

Private Sub mTextBox_KeyDown(KeyCode As Integer, Shift As Integer)
 ExpandList
End Sub

Private Sub mTextBox_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  ExpandList
End Sub
Public Sub ExpandList()
  With mListBox
    .Height = mHeightPixels
    .Top = mTextBox.Top + mTextBox.Height
    .Visible = True
    .SetFocus
    .BorderStyle = 1
  End With
End Sub
Public Sub ShrinkList()
    With mListBox
        'for some strange reason cannot make height very small such as 0. The value will not select every other time.
        .Height = 60
        .BorderStyle = 0
    End With
 End Sub

The problem is after selecting with a mouse I cannot shrink the textbox to 0 or the proper value is not always selected. So you will see a line. This does not show if you use the keys and enter to select.
 

Attachments

What I call the "line" is actually the shrunk listbox. The issue is you cannot shrink it on the mouse click because by shrinking or moving a listbox it changes what value is selected. If you do not want the arrow key feature (which is really useful) this can be coded around by using the after update instead. I think I can add a timer event to work around this issue, so that I can keep these features.
 
here check again if you can make City2 dropdown when
you Setfocus to it.

BTW, this technique works both on Single Form and datasheet view and Continuous form.
 

Attachments

What I call the "line" is actually the shrunk listbox. The issue is you cannot shrink it on the mouse click because by shrinking or moving a listbox it changes what value is selected. If you do not want the arrow key feature (which is really useful) this can be coded around by using the after update instead. I think I can add a timer event to work around this issue, so that I can keep these features.
Thank you very much.
Its not in my requirement. Not work in my computer. I can type anything in the textbox.
I just need textbox act like combo box.
Example : If you click or press TAB key the textbox then it expended drop list And user can't entered any data without have in the list. Same like combo box.
But here your field I can type. and don't have any drop down list.
 
None go
Thank you very much.
Its not in my requirement. Not work in my computer. I can type anything in the textbox.
I just need textbox act like combo box.
Example : If you click or press TAB key the textbox then it expended drop list And user can't entered any data without have in the list. Same like combo box.
But here your field I can type. and don't have any drop down list.
Not sure what you are looking at, but that is what it does.
 
sir, This is one of the example.
 

Attachments

  • 6.jpg
    6.jpg
    222.9 KB · Views: 106
The only way to do what you want to do is to use a Subform in the place of the combobox. You cannot get rid of a combobox selection arrow. Make a subform with the records you want and then just set its Height property to something that will show your records and set its Height property to whatever you want when you don't want it showing all the records. You don't have set master/child fields if you don't wish to. The subform records can still be displayed. Just use a subform and expand it or contract as you wish.
 

Users who are viewing this thread

Back
Top Bottom