Listbox not working

L

LittleAnn

I have created a template, set up a userform and added a list box, the
userform works fine with the TextBoxes but for some reason when the Userform
opens for the Userform, the listbox does nothing, i.e cant click into and it
does not show any data that I added to the below code, any ideas where I have
gone wrong??

Option Explicit

Private Sub UserForm1_Initialize()
Dim myArray1 As Variant
Dim myArray2 As Variant
Dim i As Long
myArray1 = Split("Select Identifier|Company Name 1|Company Name 2|" _
& "Company Name 3|Company Name 4", "|")
myArray2 = Split(" |1|2|3|4", "|")
Identifier.ColumnWidths = "60;0"
For i = 0 To UBound(myArray1)
ListBox.AddItem
ListBox.List(i, 0) = myArray1(i)
ListBox.List(i, 1) = myArray2(i)
Next i
End Sub


Private Sub CmdOK_Click()
Dim oRng As Word.Range
Dim oBM As Bookmarks
Set oBM = ActiveDocument.Bookmarks
Set oRng = oBM("DocumentTitle").Range
oRng.Text = DocumentTitle.Text
oBM.Add "DocumentTitle", oRng
Me.Identifier.TextColumn = 2
Set oRng = oBM("Identifier").Range
oRng.Text = Identifier.Text
oBM.Add "Identifier", oRng
Set oRng = oBM("IssueDATE").Range
oRng.Text = IssueDATE.Text
oBM.Add "IssueDATE", oRng
Set oRng = oBM("IssueSTATUS").Range
oRng.Text = IssueSTATUS.Text
oBM.Add "IssueSTATUS", oRng
Me.Hide
End Sub
 
H

Helmut Weber

Hi LittleAnn,

you may show the userform1 by userform1.show.

However, once the userform is shown,
you refer to it by just userform, not userform1.

Therefore, this one works for me:

Private Sub UserForm_Initialize()
Dim myArray1 As Variant
Dim myArray2 As Variant
Dim i As Long
myArray1 = Split("Select Identifier|Company Name 1|Company Name 2|" _
& "Company Name 3|Company Name 4", "|")
myArray2 = Split(" |1|2|3|4", "|")
' Identifier.ColumnWidths = "60;0" ' not declared
For i = 0 To UBound(myArray1)
ListBox1.AddItem
ListBox1.List(i, 0) = myArray1(i)
ListBox1.List(i, 1) = myArray2(i)
Next i
End Sub

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
A

alborg

Hi Ann:

Try changing "Private Sub UserForm1_Initialize()" to "Private Sub
UserForm_Initialize()". That fixes it...

Cheers,
Al
 

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

Similar Threads


Top