Change combobox to textbox  using vb

Posted on 2003-04-01
Medium Priority
Last Modified: 2011-10-03
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.
Question by:Rich292
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

Charityg earned 150 total points
ID: 8246618
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

Expert Comment

ID: 8246732
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


Expert Comment

ID: 8246764
Which is pretty much what I said.
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

LVL 12

Expert Comment

ID: 8246821
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!


Expert Comment

ID: 8248742
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...

Author Comment

ID: 8254102
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question