On 28 Mar 2005 00:05:36 -0800, "ironcito" <co****@ironcit o.com> wrote:
Hello!
I'm looking for a way to have a field in my database that will
automaticall y be filled with a random 4-character alphanumeric string
every time I enter a new record. Like an autonumber field, but
alphanumeric and random. Could anyone tell me how to do this? Please
explain it so that a newbie can do it. Thanks a lot, and have a nice
day! =)
Something like this, perhaps? This is untested, so it might need some
debugging.
Public function Random AlphaNumString( StringLen As Long) As String
Dim lngCharNum As Long
Dim strResult as String
strResult = Space(StringLen )
For lngCharNum = 1 to StringLen
Mid$(StringLen, lngCharNum, 1) = RandomAlphaNumC har()
Next
AlphaNumString = strResult
End Function
Public function RandomAlphaNumC har() As String
Dim lngBase36Num As Long
Randomize
lngBase36Num = Int(Rnd(1)*36)
If lngBase36Num < 10 Then
RandomAlphaNumC har = Str(lngBase36Nu m)
Else
RandomAlphaNumC har = Chr(Asc("A") + lngBase36Num - 10)
Endif
End Function