Public Function GetRandomString(ByVal iLength As Integer) As String
Dim intMax, iLoop, k, intValue, strChar, strName, intNum
' Specify the alphabet of characters to use.
Const Chars = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"
' Specify length of names.
'intMax = 5
intMax = iLength
' Specify number of names to generate.
Randomize
strName = ""
For k = 1 To intMax
' Retrieve random digit between 0 and 25 (26 possible characters).
intValue = Fix(62 * Rnd())
' Convert to character in allowed alphabet.
strChar = Mid(Chars, intValue + 1, 1)
' Build the name.
strName = strName & strChar
Next
GetRandomString = strName
End Function