' /* In A Code Module Add This: */

Public Function Gen_Rand_Password(PassLength As Integer) As String
' /* Dimension A Variable To Contain The Random Password */
Dim RetVal As String

' /* Dimension Variables To Contain The Upper and Lower Random Boundaries */
Dim Max As Integer
Dim Min As Integer

' /* Set The Limits Of Min and Max To Character Codes Relevant To The Keyboard */
Max = 126
Min = 48

' /* Set The Random Number Generator, Using Timer as the Seed */
' /* This Makes The Psuedo-Random Number A Little More Random */
Randomize Timer

' /* You Can Change This To The Desired Length, 8 is Pretty Much A */
' /* Standard Password Length */
If PassLength < 8 Then
    ' /* Return From Function With An Error */
    Gen_Rand_Password = "error: invalid length"
End If

' /* Loop Until We Reach The Desired Length Of The Password */
For I = 1 To PassLength
    ' /* Concantenate (append) RetVal with Random Keyboard Character */
    RetVal = RetVal & Chr(Int((Max - Min + 1) * Rnd + Min))
Next I

' /* Return That Value To The Calling Procedure */
Gen_Rand_Password = RetVal
End Function


' /* In Your Form (or In Another Procedure) [Call It Like This] */
' /* The Value Passed To The Function (8, In This Case) */
' /* Is The Number Characters That Will Be Returned */
RandomPassword = Gen_Rand_Password(8)
2
Contributors
1
Reply
6
Views
12 Years
Discussion Span
Last Post by willdove
0

How do I implment this into An Access form, so that I can create a random password to assign to users

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.