change control type

J

jay

--------------------------------------------------------------------------------

I am using this code to change a text box into a combo box with VBA Code.

txtBox.ControlType = acComboBox

when I run it it says "to set this property, open the form in design view"
....which defeats the purpose of doing it in VBA.

any thoughts???
 
O

Ofer Cohen

Why do you want to change the field type?

Create a text box and a combo box, one on top of the other, and set the
visiblity of each one of then

Me.TextBox.Visible = (Condition)
Me.ComboBox.Visible = Not (Condition)

So it will alwys set one to visible True and the other to False
 
C

Cheese_whiz

Hi Jay,

Why not just create two controls and show/hide them based on your needs?

CW
 
J

jay

that's what i currently have, which will work fine. just was curious to see
if i had the code wrong.
 
C

Cheese_whiz

Hi Jay,

What you appear to be attempting is actually changing the control type of a
SINGLE control back and forth depending on your needs. What I'm suggesting
(as well as the poster above me) is that you just go ahead and make TWO
controls, one of each kind (one textbox, one combo box), stack them on top of
each other so they sit in the same place on your form, and use the 'visible'
property (of each of them) to hide one and show the other one depending on
what you need.

CW
 
U

UpRider

Jay, Here's an actual example of modifying a form via VBA in design mode:
DoCmd.OpenForm "frmInputBox", acDesign
Forms!frmInputbox!lstZip.RowSource = "SELECT Zip, City, St, ZipID FROM
tblZipcode " _
& "WHERE tblZipcode.Zip=fcnZipArg(2);"
DoCmd.Close acForm, "frmInputBox", acSaveYes
DoCmd.OpenForm "frmInputBox"

HTH, UpRider
 
D

Douglas J. Steele

That's how to modify the RowSource. RowSource can be modified that way.

Jay's wanting to modify the ControlType of a control. That can't be done
unless the form is open in design mode. Of course, I can't see any reason
why you'd want to change it programmatically. If sometimes you need a text
box and sometimes a combo box, put both on the form, and only make one
visible at a time.
 
U

UpRider

Doug, I believe my code does open the form in design mode. He would
substitue his code for the rowsource code, which is only for example.
The steps are (all via VBA):

Open the form in design mode
Make the changes
Save the form with changes
Open the revised form

UpRider
 
D

Douglas J. Steele

Sorry, you're right: it is opening in Design mode.

I still don't understand the requirement to change the control type
programmatically!
 
Top