I have an Access database where I would like to create a Captcha on a Form. I'm doing it more as a test of my VBA knowledge, but I have hit a snag where I have been unable to get my code to completely randomise the string generated.
The string (displayed below the Captcha label) is what I will refer to as the Captcha string. The Captcha string is generated during the Form's On Load event using the following code:
When I open my database for the first time it loads with the Captcha string showing ZDJbagZ5 every single time.
When I close the Form (but keep the database open) and then reopen it, it shows ndzoyCaK every single time.
It seems as though it is not generating randomly like I thought the code would.
Any idea on how to fix this? I want a completely unique code each time I open the Form.
The string (displayed below the Captcha label) is what I will refer to as the Captcha string. The Captcha string is generated during the Form's On Load event using the following code:
Code:
Private Sub Form_Load()
Dim CaptchaString As String * 8
Dim n As Integer
Dim ch As Integer
For n = 1 To Len(CaptchaString)
Do
ch = Rnd() * 127
Loop While ch < 48 Or ch > 57 And ch < 65 Or ch > 90 And ch < 97 Or ch > 122
Mid(CaptchaString, n, 1) = Chr(ch)
Next
Debug.Print CaptchaString
Me.CaptchaBox.Caption = CaptchaString
CaptchaString = ""
End Sub
When I open my database for the first time it loads with the Captcha string showing ZDJbagZ5 every single time.
When I close the Form (but keep the database open) and then reopen it, it shows ndzoyCaK every single time.
It seems as though it is not generating randomly like I thought the code would.
Any idea on how to fix this? I want a completely unique code each time I open the Form.