View Full Version : Programatically change the type of a control (combo to textbox)


Alexandre
03-01-2001, 08:43 AM
I have a form linked to a table where I need to adapt the control bound to the primary key (reference) according to what the user wants to do:
With the on Clik event I ask the user if he wants to modify the reference or not (just perform Find or Select another record for example) or cancel.

Up to now, the control is a textbox. This was necessary since the Inputmask of the reference is dynamically set (depends on the value chosen by the user in another control).

Now, I would prefer the Textbox to turn into a combo populated with the references through an SQL query when the user doesn t want to modify the reference, so he could go directly to an existing one by choosing in the list.

I manage to do everything BUT programatically change the type of the contol (is ther a property for that ?).

Any help is most welcome!

PS Definitely setting the control as a combo is not satisfactory neither since the OnClik event doesn t work the same at all with combo (only tested after the user has made a choice in the list: too late!) than with a textbox.

chrismcbride
03-01-2001, 08:54 AM
A quick fix might be to create two controls pointing to the same field. Once that is done, you could simply hide one or the other depending on the state of the form. Make them the same size, put on directly on top of the other and put them right next to each other in the Tab Order...
HTH
Chris

Alexandre
03-01-2001, 09:06 AM
Chris - You re right, thank you. I was considering doing this when.. I found that a .ControlType property exists under VBA and seems to allow dynamic conversion of a control type into another... I m gonna try.

Thanks