View Single Post
 
Old 01-28-2015, 06:59 AM
Attila Attila is offline Windows XP Office 2010 64bit
Novice
 
Join Date: Jan 2015
Posts: 7
Attila is on a distinguished road
Default Selected items in Combobox remain the same when closing and reopen document

Hello there..

I am not a programmer but like to program a small project with vba.

I have a Userform1 which contains a ComboBox1.
When I now select a value in the combobox in my userform it fills the value to the variable in my word document.
When I now hide the form with "Hide Me" it hides the userform and when I then reopen the userform with the Button in the word document all the previously selected items and entered textes in textboxes remain the same. So far so good.
But when I save the document close it and reopen it again all the values selected are on default again. I would like that the selected items and textboxes are the same as I entered the first time. So I may only change a little piece and not enter the hole info again.

I thought about adding a new list entry in my combobox with values from the variable so I can choose between the default entries and the now entered value. So I could then initialize my ComboBox with this list number.

Here is my code
The text in red is what i would like to do but doesn't work


Private Sub UserForm_Initialize()

ComboBox1.ColumnCount = 2
ComboBox1.ColumnWidths = "50;20"
Dim listEntries1(3, 1) As Variant
listEntries1(0, 0) = "This"
listEntries1(0, 1) = 1
listEntries1(1, 0) = "is"
listEntries1(1, 1) = 2
listEntries1(2, 0) = "a"
listEntries1(2, 1) = 3
listEntries1(3, 0) = "Test"
listEntries1(3, 1) = 4

'listEntries1(4, 0) = ActiveDocument.Variables.Item(var1).Value
'listEntires1(4, 1) = ActiveDocument.Variables.Item(var1).Value

Me.ComboBox1.List = listEntries1

With ComboBox1
ComboBox1 = ComboBox1.List(0)
End With

End Sub

Private Sub OK_Click()

'Define the variable oVars
Set ovars = ActiveDocument.Variables
'Assign the values of the text boxes to the variables
ovars("var1").Value = Me.ComboBox1.Value
ActiveDocument.Fields.Update

Unload Me

End Sub


I searched all over the internet for a solution but didn't find one.
So please can you help?
If you can help me with a better solution that the previously selected items remain selected so please tell me.

Thank you
Reply With Quote