• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 887
  • Last Modified:

Change combobox to textbox using vb

When I choose a value from a combobox I would like that combobox to automatically convert into a textbox. I don't mind if I have to close the form and then re-enter to achieve the change. Is this possible and if so, help with the visual basic code would be appreciated.
1 Solution
Place a textbox control on top of the combobox. Set the visible property to false.

In the afterupdate event of the combobox check to see if an item was selected from the combo and if so set the visible property for the combobox to false and the visible property of the textbox to true. Then assign the value from the combobox to the textbox

Private Sub Combo0_AfterUpdate()
If Combo0.Text <> "" Then
    Text2 = Combo0.Text
    Text2.Visible = True
    Combo0.Visible = False
End If
End Sub
What do you say to have both, combo and text boexes in a same form, one above another. When you select your value from combo, set focus to text box and hide combo.


Let's suppose your combo is called cbo1 and text box is txt1. You have 2 columns in a combo: ID (hidden) and Name. Set columns count to 2 and width to 0;1

Private Sub Form_Open(Cancel As Integer)
    txt1.Visible = False
End Sub

Private Sub cbo1_AfterUpdate()
    txt1.Visible = True
    txt1 = cbo1.Column(1)
    cbo1.Visible = False
End Sub

Which is pretty much what I said.
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

he was typing while you posted (classic beat-to-the-punch game of Experts Exchange).

i have another idea. you can quickly:

DoCmd.RunCommand accmdSaveAll
DoCmd.OpenForm "CurrentFormName", acDesign
If Text1Control.ControlType = acTextBox Then Text1control.ControlType = acComboBox
DoCmd.OpenForm "CurrentFormName", acNormal

There may be another way to switch between design mode and regular mode quickly (another command. maybe DoCmd.CurrentView or something).

this is a more complicated way, but it may work.

also, for the other idea, you may want to set the control source to both of them. at run time through code or before hand.

one last note, why not just choose a combo box and set the LimitToList property to False, thus you can still type anything in the combo box. the drop down menu is more or less a "suggestion". why else do you think they call it a combo box? it combines a list box and a text box!

Just as a "keep in mind", it's generally not a good idea to overlap controls if avoidable.  Certainly there are exceptions but just as a general rule...
Rich292Author Commented:
Wow, thanks for all your help and advice guys. Have gone with Charityg as quickest off mark - sorry to others. I liked the simplicity of the solution! For what I need, overlapping the text and combo boxes shouldn't be a major problem.

Just as an aside, I found for my purposes that the code worked better in the Form OnCurrent property as:

If IsNull(Combo1) Then
Combo1.Visible = True
Text1.Visible = False
Text1 = Combo1
Text1.Visible = True
Combo1.Visible = False


Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now