PDA

View Full Version : Solved: Closing a Word document loses combo box values



will1128
08-31-2010, 09:44 AM
Hi,

I've created the attached Word 2003 form, but when I close it and re-open it loses all the List values for the combo box.

1. Why does it lose the values?
2. How do I keep the values every time the document is opened and closed?

The code I'm using to add to the values is


Public Sub ComboBox4_Change()
ComboBox4.List = Array(" ", "Plymouth", "San Antonio", "Charlotte")
End Sub

Thanks

fumei
08-31-2010, 09:58 AM
Simple. Add the values using the Document_Open event.

The document is opened...the values are added.

will1128
08-31-2010, 10:02 AM
Uh....I have no idea what that means..

How do I add a Document_Open Event?

fumei
08-31-2010, 10:16 AM
OK, if you have the code you posted - Public Sub ComboBox4_Change() - this is probably (certainly) in the ThisDocument code module.

Go to the top LEFT dropdown in the ThisDocument code module. It will show something like:

(General)
ComboBox1
ComboBox2
ComboBox3
ComboBox4
Document

Click Document. This will automatically place:
Private Sub Document_New()

End Sub
into the code module. This is the Document_New event. However, you do not care about that, so you can delete it. Notice that in the RIGHT dropdown at the top of the code module (the LEFT shows as Document), you will see "New". As you have placed the New event into the module. Select the RIGHT dropdown, and click "Open".

Voila. You now have:
Private Sub Document_Open()

End Sub
an empty Document_Open event. Put your code in there, like:

Private Sub Document_Open()
ComboBox4.List = Array(" ", "Plymouth", "San Antonio", "Charlotte")
End Sub
Every time the document is opened, the Document_Open event fires and ComboBox4 will be populated with the array.

will1128
08-31-2010, 10:23 AM
I take it when you opened the document the values were there? How come when I open a document I created the values are not there?

fumei
08-31-2010, 10:29 AM
" How come when I open a document I created the values are not there?"

Because you did not follow my instructions perhaps?

Note: you may have to download and SaveAs. For me, clicking the attached file does NOT work, as it is opened using IE as read-only.