Are you talking about some kind of an auto resize feature based on the returned data? If so, you can force a query to use a function if it is declared in a standard module. If you pass in a fieldname, then it will be run for every line of the query.
1a. Put the following in a standard module for one item
Public glngMaxLen As Long
Function GetLongestValue(pstrText As String) As String
If Len(Trim$(pstrText)) > glngMaxLen Then
glngMaxLen = Len(Trim$(pstrText))
End If
GetLongestValue = pstrTtext 'Just pass it back
End Function
1b. Put following in a standard module for multiple items
Public glngMaxLen1 As Long
Public glngMaxLen2 As Long
Function GetLongestValues(pstrText1 As String, _
pstrText2 As String) As String
If Len(Trim$(pstrText1)) > glngMaxLen1 Then
glngMaxLen1 = Len(Trim$(pstrText1))
End If
If Len(Trim$(pstrText2)) > glngMaxLen2 Then
glngMaxLen2 = Len(Trim$(pstrText2))
End If
GetLongestValues = "OK" 'Just pass something back
End Function
2. Include the above in your query
Select Field1, GetLongestValue(Field1) As Dummy
From Table1, etc
Select Field1, Field2, GetLongestValue(Field1, Field2)
From Table1, etc
3. In form Load or Open event code (must be after query)
YourListBox.ColumnWidths = glngMaxLen
YourListBox.ColumnWidths = _
glngMaxLen1 & ";" & glngMaxLen2
Good Luck!
Have a great day!
j2consulting@yahoo.com