Jonas Offersen
New Member
- Joined
- Feb 13, 2018
- Messages
- 14
So, this code isn't working for me. For whatever reason, I get an " Error 424 - object required" error, when I try to pass the object into the sub.
I do not get this error when I try to use it outside of the function.
The code bellow is altering the textbox columns as working as intended.
As it turns out I don't actually need this right now. But I would like to know what I'm doing wrong regardless, for next time.
I do not get this error when I try to use it outside of the function.
Code:
Private Sub Form_Load()
Dim obj As ListBox
Set obj = Me.ListNiveau
obj.visible = False [COLOR=#0000ff]'This is working![/COLOR]
LayoutControls.SetListBoxColWidths (obj) [COLOR=#0000ff]'This returns error 424.[/COLOR]
End Sub
The code bellow is altering the textbox columns as working as intended.
Code:
Public Sub SetListBoxColWidths(ListBoxName As ListBox)
Dim i As Integer
Dim j As Integer
Dim ColMaxWidth(2) As Double ' for 3 column listbox
[COLOR=#0000ff]
'Initialise to zero[/COLOR]
For j = 0 To 2
ColMaxWidth(j) = 0
Next j
[COLOR=#0000ff]
'itereate thru each item in listbox and find max size[/COLOR]
For i = 0 To ListBoxName.ListCount - 1
For j = 0 To 2
If ColMaxWidth(j) < (Len(ListBoxName.Column(j, i)) * 125) Then
ColMaxWidth(j) = (Len(ListBoxName.Column(j, i)) * 125)
End If
Next j
Next i
[COLOR=#0000ff]
'display columnwidths based on max size[/COLOR]
ListBoxName.ColumnWidths = ColMaxWidth(0) & ";" & ColMaxWidth(1) & ";" & ColMaxWidth(2) & ""
End Sub
As it turns out I don't actually need this right now. But I would like to know what I'm doing wrong regardless, for next time.