Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default ListBox items disappear upon Show statement

Hello -

I'm using Excel 2000 VBA to programmatically create a userform
containing a listbox. I can watch the userform as it is created and
filled (via the debugger), but as soon as the show line executes, the
listbox entries disappear - other items, such as checkbox labels &
buttons appear fine.

Can someone tell me how to solve this problem, and more importantly,
why it is occuring?

I have one other question also: A width property can be set for an
item such as a command button however that property is neither seen in
the complete_word dropdown list nor in the object browser for the item
- it can be seen in the Properties Window, however. Why ??

Thanks in advance, (Please post any replies, as I cannot access the
email acct easily).

Keb


Here is a simplified version of my code:

Sub ShowListbox()
Dim TempForm
Dim NewListBox As MSForms.ListBox
Dim i As Integer

Application.VBE.MainWindow.Visible = False
'
' Create the userform
'
Set TempForm = ThisWorkbook.VBProject.VBComponents.Add(3)
TempForm.Properties("Width") = 100
'
' Add listbox & populate it.
'
Set NewListBox = TempForm.Designer.Controls.Add("forms.ListBox.1", , True)

For i = 1 To 10
NewListBox.AddItem "Item " & LTrim(Str(i))
Next
'
' Show the form.
'
VBA.UserForms.Add(TempForm.Name).Show
'
' Delete the form & clean up.
'
ThisWorkbook.VBProject.VBComponents.Remove VBComponent:=TempForm

Set TempForm = Nothing
Set NewListBox = Nothing
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 459
Default ListBox items disappear upon Show statement

My understanding is that when s form is shown its 'design' instance is
destroyed and a run-time instance created. Therefore, when I ran your
code in Excel2000 I got the expected results i.e. a visible but
unpopulated listbox.

Here's an amendment:

'
' Show the form.
'
Dim frm As Object
Set frm = VBA.UserForms.Add(TempForm.Name)
Set NewListBox = frm.ListBox1
For i = 1 To 10
NewListBox.AddItem "Item " & LTrim(Str(i))
Next

frm.Show
Set frm = Nothing
'
' Delete the form & clean up.
'

--
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default ListBox items disappear upon Show statement

Thanks, onedaywhen - Appreciate the explanation and sample (working) code!

Cheers, keb
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
filtering to show items in a listbox eileenj Excel Discussion (Misc queries) 1 August 11th 06 01:30 PM
Adding Items to a ListBox-Unique Items Only jpendegraft[_14_] Excel Programming 2 May 2nd 04 02:27 AM
Items in a Listbox Todd Huttenstine Excel Programming 1 April 26th 04 03:36 PM
Sort Listbox Items Stratuser Excel Programming 2 January 17th 04 03:05 PM
Listbox--moving items up or down libby Excel Programming 0 November 7th 03 06:53 PM


All times are GMT +1. The time now is 11:13 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"