Hi Les
You can use a user-defined function in an update query, but you need to fool
the query optimizer. You might expect this to work::
Update tblAssociate_Details set strAssociate_Password = RandomLetter()
However, because no argument is being passed to the function, the optimizer
assumes the same result will be returned every time, so your function will
be called only once and every record will get the same password.
You can trick it by passing the primary key of the record as a dummy
argument:
Function RandomLetter(Optional Length As Integer = 8, _
Optional Dummy as Variant) As String
Then, the SQL:
Update tblAssociate_Details
set strAssociate_Password = RandomLetter(8, AssociateID)
--
Good Luck!
Graham Mandeno [Access MVP]
Auckland, New Zealand
Les said:
Chris thanks for this it's just what I need.
Do you by any chance have the code so I can run an update query and update
the whole table in one go my table is "tblAssociate_Details and the field"
name is "strAsssociate_Password"
Thanks
Les
Here's a function for you.
Function RandomLetter(Optional Length As Integer = 8) As
String
Randomize
'For Upper case Only
Dim intLetter As Integer
Dim intCounter As Integer
' For intCounter = 1 To Length
' intLetter = Int(Rnd(1) * 26 + 65)
' RandomLetter = RandomLetter & Chr$(intLetter)
' Next intCounter
'For Mixed Case
Dim intUpper As Integer
For intCounter = 1 To Length
intUpper = Int(Rnd(1) * 2)
If intUpper Then
intLetter = Int(Rnd(1) * 26 + 65)
Else
intLetter = Int(Rnd(1) * 26 + 97)
End If
RandomLetter = RandomLetter & Chr$(intLetter)
Next intCounter
End Function
There's no check for duplicity, but the chances are very
slim that it would happen.
Chris
-----Original Message-----
I need to generate a random password entirely text. Is
there an easy way to
do this.
This needs to be of 8 characters and cannot be repeated.
I expect to need a
maximum of 800.
Thanks
Les
.