|
|
CODE Public Function myRandStr(nm As String)
' Code courtesy of UtterAccess Wiki ' http://www.utteraccess.com/wiki/index.php/Category:FunctionLibrary ' Original submission by Mark Davis (aka: Cybercow) ' Date contributed - Aug, 11, 2010 ' ' You are free to use it in any application, ' provided this copyright notice is left unchanged. ' ' Randomizes Text Strings and/or numbers ' Usage: In a query - NameOfFieldRnd: myRandStr([NameOfField]) ' In a Form Control's "ControlSource" property - =myRandStr([NameOfField]) ' Test in debug window - ?myRandStr("1M3G5D7lower case too") Dim myChr As String Dim myAsc As Integer 10 myRandStr = "" 20 For I = 1 To Len(nm) 30 myChr = mid(nm, I, 1) 40 If Asc(myChr) >= 65 And Asc(myChr) <= 90 Then ' Upper Case Letters 50 myAsc = Int((90 - 65 + 1) * Rnd + 65) 60 ElseIf Asc(myChr) >= 97 And Asc(myChr) <= 122 Then ' Lower Case Letters 70 myAsc = Int((122 - 97 + 1) * Rnd + 97) 80 ElseIf Asc(myChr) >= 48 And Asc(myChr) <= 57 Then ' Numerals 90 myAsc = Int((57 - 48 + 1) * Rnd + 48) Else 110 myAsc = Asc(myChr) 120 End If 130 myChr = Chr(myAsc) 140 myRandStr = myRandStr & myChr Next I End Function
|
| This page was last modified 09:40, 6 April 2011. This page has been accessed 743 times. Disclaimers |