Re: How do I populate my combobox - I know...it's been asked. by Doug
Doug
Sat Mar 15 01:58:04 PDT 2008
I think this gets back to the way in which you are calling the userform.
Usually, you can get away with
UserForm.Show
Purists inside on using the following method (in this case the userform has
been given the name of frmMemo)
Dim myForm As frmMemo
Set myForm = New frmMemo
myForm.Show vbModal
Unload myForm
Set myForm = Nothing
With this method, when the userform is closed, it is removed from memory by
the Set myForm = Nothing. As a result, the next time it is used, it has to
be initialized and that is when the items are added to the combobox.
With the simple userform.Show method, the userform is probably remaining in
memory and as a result is not be initialized again (though I must admit, if
it did remain in memory, I would expect the items still to be loaded into
the combobox.
So, you can either stick with what you have now (using the DropButtonClick
event) or try using the above method of calling the form, or another thing
that would probably cause the combobox items to be reloaded would be to put
the code that does that into the UserForm_Activate event.
--
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
"lkgoldie" <lkgoldie@discussions.microsoft.com> wrote in message
news:FD7392A6-D515-4689-9C7A-2B0B230E54C5@microsoft.com...
> Before I make things more confusing let me try to answer your questions...
> I can tell the rest of my list is gone cause when I click on it nothing
> appears.
> The combobox is enabled and I did use a template (.dotfile). I still have
> the same problem of my list items in my combo box not reappearing after I
> save and reopen.
> Now to make it confusing....I found an older thread with someone with a
> very
> similar problem....you had replied with the following advise......
> -------------------------------------------------------------------------------------------------
>
> 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.
>
> -----------------------------------------------------------------------------------------------
> I copy and pasted the code above - saved it and reopened....sure enough
> the
> list was there!
> not sure what I am doing but I am sure the problem is with my limited
> knowledge!
>
> Thanks for taking the time to help us all on this thread.....in my
> searches
> I see you are very popular!
>
> Lisa
>
>
>
> "Doug Robbins - Word MVP" wrote:
>
>> If the Properties window is not displayed in the Visual Basic Editor, use
>> the View menu to display it. Then when you select the combobox on the
>> userform, its properties will be displayed in the Properties window. One
>> of
>> those properties is the "Enabled" attribute of the control.
>>
>> I still do not really understand how you are using this form. The form
>> should be in a template (.dot file) which should have an autonew macro in
>> it
>> that calls the form. Then when you create a new document from the
>> template,
>> that macro will run and cause the form to be displayed, which triggers
>> the
>> Initialize event of the form to populate the combobox.
>>
>> Actually, how do you know the rest are gone. Does nothing appear when
>> you
>> use the down arrow on the combobox?
>>
>> --
>> 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
>>
>> "lkgoldie" <lkgoldie@discussions.microsoft.com> wrote in message
>> news:D6DD0C7D-D67F-4BFF-9E35-63EAA89F19A0@microsoft.com...
>> > You truly are talking to a newbie.......How do I tell if the comboox is
>> > enabled?
>> >
>> > I save my document before closing (all information in my combobox is
>> > there)
>> > when I return to open the document only the first item in my combo box
>> > is
>> > there and the rest are gone. When I go to look at the script/code it is
>> > there
>> > and I can run it again but I was looking for a way that when I reopen
>> > my
>> > document after saving it that all information in my combo box stays.
>> > Thanks
>> > for any help!
>> >
>> > Lisa
>> >
>> > "Doug Robbins - Word MVP" wrote:
>> >
>> >> Is the combobox enabled?
>> >>
>> >> When you say "save and reopen" do you mean use save, close and then
>> >> use
>> >> File>New and select the template containing the userform as the basis
>> >> for
>> >> the new document?
>> >>
>> >> --
>> >> 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
>> >>
>> >> "lkgoldie" <lkgoldie@discussions.microsoft.com> wrote in message
>> >> news:5E09DE30-CF90-4C0F-8E0E-D6B4308589E5@microsoft.com...
>> >> >I have reviewed other posts that mirror my hicup but I just don't
>> >> >seem
>> >> >to
>> >> >be
>> >> > getting it!
>> >> >
>> >> > I am using the following (as a general example)
>> >> >
>> >> > Private Sub UserForm_Initialize()
>> >> > ' set up the combo box list
>> >> > With ComboBox1
>> >> > .AddItem "Jan"
>> >> > .AddItem "Feb"
>> >> > .AddItem "March"
>> >> > .AddItem "April"
>> >> > .AddItem "May"
>> >> > .AddItem "June"
>> >> > .AddItem "August"
>> >> > .AddItem "Sept"
>> >> > .AddItem "Oct"
>> >> > .AddItem "Nov"
>> >> > .AddItem "Dec"
>> >> > .ListIndex = 0
>> >> > End With
>> >> > End Sub
>> >> >
>> >> > All works fine till I save and reopen. Only Jan shows with the rest
>> >> > of
>> >> > the
>> >> > list gone. From what I have got....I did lower my macro security to
>> >> > MED
>> >> > and
>> >> > clicked the option of trust all...still have the problem.
>> >> >
>> >> > I plan on using this script three times but w/ different information
>> >> > (Months, Names and Locations). Is there a 'general' script line I
>> >> > can
>> >> > use
>> >> > to
>> >> > make sure all of my combo box is saved and there when I reopen it?
>> >> >
>> >> > Thanks
>> >> > Lisa
>> >> >
>> >>
>> >>
>> >>
>>
>>
>>