Populate field of new record with random word (1 Viewer)

D-Angle

Registered User.
Local time
Today, 12:02
Joined
Nov 9, 2015
Messages
26
I am trying to add a random 'password' to each new record in a table to be used over the phone when discussing information. Basically it would be a random word that both parties in the conversatiuon would have if they needed to verify identity, as a form of low level security.

I have a table TBL_PsWrd that has a list of 235 random words and an Autonumber field to give each one a unique ID, and I would like the form to assign one of these words at random to each new record when it is created. So in a continuous records form, you would click to create a new record, and the password field would automatically be populated with a random word from this list. Is this possible?
 

cyanidem

Nieóhfytny jaszczomp
Local time
Today, 12:02
Joined
Nov 30, 2015
Messages
106
Code:
PasswordField=DLookUp("[RandomWord]", "TBL_PsWrd", chr(39) & "[RndWrdID]=" & Int ((253 - 1 + 1) * Rnd + 1) & chr(39))

This
Code:
Int ((253 - 1 + 1) * Rnd + 1)
will produce "random" number between 1 and 253 (ID of your random word)
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:02
Joined
May 7, 2009
Messages
19,249
sample password generator that you can use:
Code:
Public Function pwdGenerator()
Dim i As Long
Dim t As Double
t = Timer
i = Val(Replace(LTrim(Rnd()), "0.", "")) Mod 235
While Timer < t + 0.2
    i = i + 1
    If i > 235 Then i = 0
Wend
pwdGenerator = Nz(DLookup("[COLOR=Blue]passfield[/COLOR]", "tbl_pswrd", "[id] = " & i), DMin("[COLOR=Blue]pasfield[/COLOR]", "tbl_pwsrd"))
End Function
just replace the blue-colored fieldname with the correct fieldname in your table.
 
Last edited:

D-Angle

Registered User.
Local time
Today, 12:02
Joined
Nov 9, 2015
Messages
26
sample password generator that you can use:
Code:
Public Function pwdGenerator()
Dim i As Long
Dim t As Double
t = Timer
i = Val(Replace(LTrim(Rnd()), "0.", "")) Mod 235
While Timer < t + 0.2
    i = i + 1
    If i > 235 Then i = 0
Wend
pwdGenerator = Nz(DLookup("[COLOR=blue]passfield[/COLOR]", "tbl_pswrd", "[id] = " & i), DMin("[COLOR=blue]pasfield[/COLOR]", "tbl_pwsrd"))
End Function
just replace the blue-colored fieldname with the correct fieldname in your table.
This is great, but how do I employ it in the form? I tried creating a module called pwdGenerator with the code above, then making a plain text box for the Password field, and setting the validation rule as pwdGenerator(), but the field is blank when I try it. I also tried creating an unbound text box and pointing it towards the module, but it gave a ?Name error.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:02
Joined
May 7, 2009
Messages
19,249
I have a table TBL_PsWrd that has a list of 235 random words and an Autonumber field to give each one a unique ID, and I would like the form to assign one of these words at random to each new record when it is created. So in a continuous records form, you would click to create a new record, and the password field would automatically be populated with a random word from this list. Is this possible?
you set the Default Value property of your textbox to:

=pwdGenerator()

since it is computer generated, you might want to disable edit on this control by setting its Locked property to Yes.
 

D-Angle

Registered User.
Local time
Today, 12:02
Joined
Nov 9, 2015
Messages
26
That's still not working, the field is still blank. In the continuous forms view, the row displays '#Name?' on the bottom row that is for creating a new record. It then goes blank once you start entering data on that row.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:02
Joined
May 7, 2009
Messages
19,249
you can upload a sample db to work with.
 

Users who are viewing this thread

Top Bottom