Rich292
asked on
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Which is pretty much what I said.
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!
andrew
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!
andrew
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...
ASKER
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
Else
Text1 = Combo1
Text1.Visible = True
Combo1.Visible = False
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
Else
Text1 = Combo1
Text1.Visible = True
Combo1.Visible = False
Example:
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)
txt1.SetFocus
cbo1.Visible = False
End Sub