Hi all,
I can't wrap my head around this. I have a userform that will resize frames and listboxes based on the number files in the folder. However the resize doesn't work unless I input either 'DoEvents' or 'Wait' into the code.
The code is in the form and not in a separate module.
Explanation would be appreciated
Thanks
I can't wrap my head around this. I have a userform that will resize frames and listboxes based on the number files in the folder. However the resize doesn't work unless I input either 'DoEvents' or 'Wait' into the code.
The code is in the form and not in a separate module.
Code:
Private Sub PeriodBox_Click()Dim Recs As String
Dim CountRecs As MSForms.Label
Dim i As Long
With RecsForm
.ScrollBars = fmScrollBarsNone
.Width = 436
.Height = 120.75
End With
'add recs to listbox if available
If Dir(path & FYBox.Value & "\" & PeriodBox.Value & "\Intercompany Recs * # *") <> "" Then
FileBox.Clear
Frame1.Clear
Frame2.Clear
Frame3.Clear
Frame4.Clear
Recs = Dir(path & FYBox.Value & "\" & PeriodBox.Value & "\")
Do While Recs <> ""
If Recs Like "Intercompany Recs* [#] *" Then FileBox.AddItem "IC Rec | " & Right(Recs, 9)
Recs = Dir
Loop
'set height based on number of recs
[COLOR=#ff0000][/COLOR][U][B]If FileBox.ListCount < 9 Then FileBox.Height = 85 Else FileBox.Height = FileBox.ListCount * 10[/B][/U][COLOR=#ff0000][U][B] - this doesn't work if below Wait or DoEvents is added, why?[/B][/U][/COLOR]
[U][B]Application.Wait (Now + TimeValue("0:00:1"))[/B][/U]
Frame1.Height = FileBox.Height + 18
Frame2.Height = FileBox.Height + 18
Frame3.Height = FileBox.Height + 18
Frame4.Height = FileBox.Height + 18
If 150 + FileBox.Height < Application.Height - 20 Then RecsForm.Height = 150 + FileBox.Height Else RecsForm.Height = Application.Height - 20
If FileBox.ListCount * 20 > Application.Height Then
With RecsForm
.ScrollBars = fmScrollBarsVertical
.ScrollHeight = FileBox.ListCount * 12
.Width = 446
.FileBox.SetFocus
.ScrollTop = 0
End With
End If
'rec counter
Set CountRecs = RecsForm.Controls.Add("Forms.Label.1")
With CountRecs
.Visible = True
.Name = "RecsCount"
.Caption = "Count: " & FileBox.ListCount
.Top = FileBox.Height + 102
.Left = 20
End With
If RecsForm.Height < 120.75 Then RecsForm.Height = 120.75
[U][B] FileBox.ListIndex = -1 - [COLOR=#ff0000]this line also doesn't work without Wait or DoEvents[/COLOR][/B][/U]
End If
End Sub
Explanation would be appreciated
Thanks