combo box drop down field

J

Josie

Hey,
I have created a combo box in a document and have managed to populate this
with the options i want to drop down - The only problem is once i have done
this and save and close the document then reopen again - the options disapeer
from the combo box and i have to go back into the VBA and click on "run sub
user form" Then The options appear again.

i really hope there is a way i can save this file whereby the sub user form
will automatically run (like macro) to fill the drop down box, but stay with
password protection as i dont want anyone else to modify the document in any
way.. I know of things like macro however it doesnt seem to give me the
option in VBA. I have tried everywhere to get an answer - please someone
help!
 
C

Cindy M.

Hi =?Utf-8?B?Sm9zaWU=?=,
I have created a combo box in a document and have managed to populate this
with the options i want to drop down - The only problem is once i have done
this and save and close the document then reopen again - the options disapeer
from the combo box and i have to go back into the VBA and click on "run sub
user form" Then The options appear again.

i really hope there is a way i can save this file whereby the sub user form
will automatically run (like macro) to fill the drop down box, but stay with
password protection as i dont want anyone else to modify the document in any
way.. I know of things like macro however it doesnt seem to give me the
option in VBA.
Put the code that fills the combobox into its own Sub. Name this sub AutoOpen
and it will execute whenever the document is opened.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
J

Josie

Hi Cindy,

Many Thanks for your reply. You have put me on the right track however i
still seem to be having problems....

I shall explain...

Since using your solution i opened my document and viewed the code for the
combo box - i then clicked on:

Insert - Proceedure
Name - AutoOpen
Type - Sub
Scope - Private

once this was complete i entered the following code:

Private Sub AutoOpen ()

End Sub

Private Sub CommandButton1_Click()
ComboBox1.DropDown
End Sub

Private Sub UserForm_Initialize()
ComboBox1.AddItem"Item1"
ComboBox1.AddItem"Item2"
ComboBox1.AddItem"Item3"
ComboBox1.AddItem"Item4"

End Sub

---------

Once i have put this information in and Run the form - save and close and
reopen again, the drop down field Still only contains the first item and the
rest of the box is blank - i have to view code for combo box - run sub user
form again and then the fields are complete.

Because this will need to be a secure document i really need for this to
work first time when opened.... Sorry to sound dumb... I really appreciate
your help.

p.s - is there any way i could mail the form to you?

Thanks again
 
K

KR

Try this small tweak:
Private Sub AutoOpen ()
UserForm_Initialize '<--add this line
End Sub
 
J

Josie

I have tried this but still no success - it was looking possitive but still
the drop down field does not get populated when re-opening the document.

I am soo frustrated and desperate to get this to work as it is a form for
work..

Please can anyone with any ideas please do a step by step on how this can be
done -

Ie.. 1 Combo Box with 8 items to choose that populates autopmatically when
the doc is opended - i do need to have the doc protected and only has certain
fields for text input.

Is there an AutoOpen macro that can run to automate the sub form?

I will be so grateful for any suggestions and help

Cheers

Josie
(Having An Extended Blonde Moment!!!) :(
 
D

Doug Robbins - Word MVP

I would suggest that instead of putting the combobox in the document, the
combobox should be in a userform in the template from which the document is
created.

See the article "How to create a Userform" at:

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


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
J

Josie

I really need for the box to be set within the document and not as a pop up
as it only relates to one question on the whole document which is mid way
down the page - and also i have to make the page as easy as possible so a
wide range of users can use this.

Are there no "wizards" that you can use to insert a combo box and auto add
the items you want? I didnt expect someone to be an absolute programming
champion to be able to insert what should be such a simple item...

Is it that there is no way to have a combo box automatically fill with
contents when the document is opened?
 
D

Doug Robbins - Word MVP

OK, there are a number of things here:

1. If you put a combobox directly in a document, then code must be run to
populate it.

2. If the macro security level is set to high, the macros in the document
will be disabled without the user being aware of that fact (That is almost
certainly what is happening in your case)

3. If the macro security level is set to medium, the user will receive a
warning message when they open the document and they will have the option to
either enable or disable the macros in the document. If they disable the
macros, your combobox will not be populated; If they enable them, code such
as the following in the ThisDocument module can be used to populate the
combobox when they click on the drop button of the combobox

Private Sub ComboBox1_DropButtonClick()

Dim i as Long
For i = 1 to 10
ComboBox1.AddItem "Item" & i
Next i
End Sub

I would never put a combobox directly into a document because of this macro
security issue.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
G

Glenn

Cindy,

I'm not much of a programmer but have found this way to keep selection in a
combobox field once you save document and then reopen it. I'm using a
template file (*.dot) and saving filled in form as a doc. Here's a snipit of
a combobox from my form. Hope it helps.
Note - cBO2.EnterFieldBehavior = fmEnterFieldBehaviorRecallSelection at end
of list.

Sub FillList2()
Set cBO2 = ActiveDocument.ComboBox2

With cBO2
.AddItem "Select Shift", 0
.AddItem "P Shift", 1
.AddItem "Q Shift", 2
.AddItem "R Shift", 3
.AddItem "S Shift", 4
.AddItem "Cold Rolling", 5
.AddItem "Hot Rolling", 6
.AddItem "Roll Shop", 7
.AddItem "Auto Shop", 8
.AddItem "Core Area", 9
.AddItem "Finishing", 10
.AddItem "N. Casting", 11
.AddItem "S. Casting", 12
cBO2.EnterFieldBehavior = fmEnterFieldBehaviorRecallSelection

End With

Set cBO2 = Nothing

End Sub
 

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