Would this also work if I call it from a code procedure that adds the
record
for new exhibitors?
--
Amy E. Baggott
"I''m going crazy and I''m taking all of you with me!" -- Linda Grayson
:
Okay. I didn't realize that you needed to use it in a query. For a
query,
you have to make just a couple of changes:
Change the Function line to this:
Function CreateRandomPassword(strlen As Integer, Optional seed as
Variant)
As String
Oddly, you don't actually have to USE seed anywhere in the function.
Then
when you call the function in the Update Query, just pass the Primary
Key
value (and autonumber is best) to the function as the seed value, like
this:
Update Customer Set CustPassword = CreateRandomPassword(10,[CustID])
I've put a small sample on my website (
www.rogersaccesslibrary.com)
called
"PasswordGenerator" which illustrates this.
--
--Roger Carlson
MS Access MVP
Access Database Samples:
www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
message
When I use it in an update query, it's generating the same password
every
time. I need a unique password for each exhibitor.
TNX
--
Amy E. Baggott
"I''m going crazy and I''m taking all of you with me!" -- Linda
Grayson
:
No built in method, but here's a little function you can use. It
will
create a password of numbers, uppercase letters and lowercase
letters.
Put
it in a global module and call it like this:
strPassword = CreateRandomPassword(10)
-----------------------------
Function CreateRandomPassword(strlen) As String
On Error GoTo Err_RandomizeCharacterField
Dim i As Integer, j As Integer
Dim strSource As String
Dim strTarget As String
Randomize
strSource = "12345678901234567890" & _
"abcdefghijklmnopqrstuvwxyz" & _
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
strTarget = ""
For i = 1 To strlen
'*** select a character position at random
j = Int((Len(strSource) - 1) * Rnd + 1)
strTarget = strTarget & Mid(strSource, j, 1)
Next
'*** when the Target String is complete, pass it back
CreateRandomPassword = strTarget
Exit_RandomizeCharacterField:
Exit Function
Err_RandomizeCharacterField:
MsgBox Err.Description
Resume Exit_RandomizeCharacterField
End Function
--------------------------
--
--Roger Carlson
MS Access MVP
Access Database Samples:
www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
message
I have a list of exhibitors for whom I would like to generate
random
passwords for a web site. Does Access have any way of generating
a
random
string of letters and numbers of a specified length (say 6)?
--
Amy E. Baggott
"I''m going crazy and I''m taking all of you with me!" -- Linda
Grayson