[RESOLVED] Form Repainting not Working
Hi
In the folloing code I am populating a multiselect listbox "LBox_Varied" based on a passed Range object "MyRange". This runs when the User form in opened.
At the end of the code I am trying to resize the listbox to fit the number of records.
----.Height = .ListCount * RowHeight----
My problem is that the form will not normally repaint, but if I include a msgbox command (commented out in the attached) it does repaint.
Any ideas?
Thanks
Declan
VB Code:
Private Sub UserForm_Initialize()
Dim DimName As String
Dim RowHeight As Integer
DimName = MyRange.Worksheet.Name
DimName = Right(DimName, Len(DimName) - 1)
DimName = Replace(DimName, "_", " ")
Me.Caption = "Select " & DimName
RowHeight = 14
With Me.LBox_Varied
.List = MyRange.Value
For MyItem = 1 To .ListCount
.Selected(MyItem - 1) = .List(MyItem - 1, 1)
Next MyItem
.Height = .ListCount * RowHeight
End With
Me.Repaint
'msgbox "anything"
End Sub
Re: Form Repainting not Working
Have you tried DoEvents after the repaint??
Re: Form Repainting not Working
Great, that worked.
Just for my education, do you know why I needed to do this?
Per the VB help file it would appear that the repaint method on its on should work.
Quote:
"The Repaint method is useful if the contents or appearance of an object changes significantly, and you don't want to wait until the system automatically repaints the area."