txtbox changed to combo box by vba

S

seeker

When a text box is right clicked an option box appears which gives change to
as an option to change the text box to a different control. When the current
record is new I would like the text box to change to a combo box to simplify
and assure correct data entry. How can this be done other than oncurrent
if me.newrecord then
cmbMembername.visible = true
text53..visible = false
else
cmbmembername.visible = false
text53.visible = true
end if

Thanks in advance
 
J

Jack Leach

I'm not sure that there's any better way other than what you already have. I
don't think you can change control types through code (at runtime), so I
would think you would want to stack a text and combo bound to the same field,
toggling visibility (as you appear to be doing).

I'm also pretty sure that a Me.Newrecord check on Current is the best way to
handle it. At least for me, many forms have that check in the current event
and takes some action for a new record. I'm pretty sure it's a common (maybe
the only way) to do it. I think your current code may already be the ideal
way to do it.

--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
S

seeker

if i wanted to vary the width of the combo box and position what does this
rate at inches? pixels?

cmbmembername.width = 1.3333

the reason i ask is because on property sheet it is 1.3333" but code does
not accept that so the above creates a very fine slit. I have tried
"1.3333"" and that does not work nor does 1.3333". Thanks for your wise help.
 
J

Jack Leach

This is actually a unit called Twips (twentieth of an imperial inch). 1 inch
= 1440 twips. When setting any screen measurements from vba, it will always
be in twips (even if the properties box lets you enter in inches).

For anything not pixel related, you can use a straight conversion from
inches to twips:

Me.Combo.Width = (1.3333 * 1440)

But a pixel to twips conversion requires the use of an API, as pixels are
set in varying resolutions. I don't think there's any pixel set values for
this stuff though. The only time I've needed that is when determining how
many twips wide and tall the screen is so I can fit forms into a maximized
window.

--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
S

seeker

Thanks that is just exactly what i needed.

Jack Leach said:
This is actually a unit called Twips (twentieth of an imperial inch). 1 inch
= 1440 twips. When setting any screen measurements from vba, it will always
be in twips (even if the properties box lets you enter in inches).

For anything not pixel related, you can use a straight conversion from
inches to twips:

Me.Combo.Width = (1.3333 * 1440)

But a pixel to twips conversion requires the use of an API, as pixels are
set in varying resolutions. I don't think there's any pixel set values for
this stuff though. The only time I've needed that is when determining how
many twips wide and tall the screen is so I can fit forms into a maximized
window.

--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top