Length of items in drop-down form field

B

bandwagon

Hi - just a quick question about using drop-down form fields in a
protect form Word document.

I need to be able to allow users to select from a list of items which
may be very long (up to 100 chars).

But a drop-down will not allow you to enter text items in it that long
(in the properties dialog). So I have written code to populate the
drop-down, which works well.

But when you then select a long item, it scrolls off the edge of the
page. It will not word-wrap to the next line - and looks terrible when
you print or print preview.

I cannot find any way to make a drop-down behave better with long text
items.

I have done a work around where when you exit the drop-down it
replaces the drop-down field with a textinput field and then inserts
the full text that I need. This then looks good - and word wraps, but
the user obviously cannot change their minds and then select another
item.

Also - it is getting very messy turning protection on and off -
because any form field which was filled in then clears when you turn
protection back on again!!! (am I doing something wrong here)

Any ideas about making drop-downs behave better?

Or how to stop form fields clearing when I turn protection back on
again? I suspect I may have to write more code to loop through them
all - save their values to an array - then when I protect again, loop
through, populating them back again! Aaargghh.


Thanks for your time


Paul Smith
 
J

Jay Freedman

Stopping the clearing of form fields when reprotecting the form is the easy
part. The Protect method takes an optional Boolean argument, NoReset, which
defaults to False. Set it to True to keep the values in the fields:

ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _
NoReset:=True

I'll suggest that the best solution is to start with a text form field in the
document, and create a userform that gets launched by the field's Entry macro.
Put the dropdown (or, better, a list box) on the userform; this can be as wide
as you need to make it. When the user clicks the userform's OK button, the
selected item from the list box is written into the text form field in the
document. If the user wants to change the field's contents, tabbing or clicking
into the field will launch the userform again.

See http://www.word.mvps.org/FAQs/Userforms/CreateAUserForm.htm.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all
may benefit.
 
S

smithy241

Jay - thanks for that! The NoReset was a stupid error - I cut and
pasted some code and it had it had 'NoReset:=False' in it!

I don't like the thought of a userform to handle this - since I am
using other dropdowns and it would be nice for them all to look and
feel the same.

I have managed to code a workable solution. OnExit from the dropdown I
convert it in to a textinput. Then OnEntry to that TextInput I convert
it back in to a DopDown!!

Seems a bit silly I need all that code to get it done - what should
have been an hour job has taken me a much longer time!

Cheers

Paul Smith
 

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