Link to home
Start Free TrialLog in
Avatar of holgrave
holgraveFlag for United Kingdom of Great Britain and Northern Ireland

asked on

acCmdChangeToTextBox

I am trying to change a combobox to a textbox in VBA on form in design mode.

I have a number of controls on the form

cntrl1
cntrl2
cntrl3

My question is how do I select the control before applying the change.

Private Sub MyChangeControlType()

  'What goes here before calling the following??

  RunCommand acCmdChangeToTextBox

End Sub
Avatar of peter57r
peter57r
Flag of United Kingdom of Great Britain and Northern Ireland image

Hello holgrave,

This is a messy operation.
Why not put a textbox and a combo on the form in the same location and make one or other of them visible as required.
This can be done while the form is being used and does not require the form to be opened in design view.

Pete
Avatar of holgrave

ASKER

Thanks for the feedback Peter57r.

However the form the controls is on will be shown in Datasheet view only...so having two controls would present the problem of 'moving the columns' around in code....which I REALLY don't have a clue how to do.

I decided to stick with my own solution of changing a combobox to a textbox in VBA in design mode. Here's how:

  If ctrl.ControlType = acTextBox Then
      ctrl.ControlType = acComboBox
  Else
      ctrl.ControlType = acTextBox
  End If

Please note, if you want to change the name of the control as well (as I did) you have to make the calls in the following order otherwise Access throws a 2467 application errors.

       ctrl.Name = "New Name"
       ctrl.ControlType = acTextBox

As I have answered my own question I think I will ask for a refund of my points....unless you object Pete??
ASKER CERTIFIED SOLUTION
Avatar of ee_ai_construct
ee_ai_construct
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial