That function is to create a fixed length string by 'padding' with a repeated character. I think it determines the output length dynamically from the listbox properties. I do 'padding' with a very simple function. My code has an argument for the total string length. So if you want to specify the output length, here is the procedure.
Code:
Function Pad(varText As Variant, strAlign As String, intLength As Integer, Optional strFill As String = " ") As String
If Len(varText) >= intLength Then
'if the source string is longer than the specified length, return the Length left characters
Pad = Left(varText, intLength)
ElseIf strAlign = "L" Then
'text aligns left, fill out the right with spaces
Pad = varText & String(intLength - Len(varText), strFill)
Else
'text aligns right, fill out the left with spaces
Pad = String(intLength - Len(varText), strFill) & varText
End If
End Function
Example of calling the function:
Pad([fieldname], "R", 15, " ")
However, this code will error if the input for varText is Null. So deal with possible null:
Pad(Nz([fieldname],""), "R", 15, " ")
I will try to debug your procedure later.