Generating passwords automatically

  • Thread starter Thread starter Amy Blankenship
  • Start date Start date
A

Amy Blankenship

I've created a Password function that creates a random password

Function Password(passlength) As String
Dim i As Integer, tmp As String, tmpChar As String, arrChars(61) As
String, j As Integer
For i = 0 To 9
arrChars(j) = i
j = j + 1
Next
For i = 65 To 90
arrChars(j) = Chr(i)
j = j + 1
Next
For i = 97 To 122
arrChars(j) = Chr(i)
j = j + 1
Next
For i = 1 To passlength
Randomize
tmpChar = arrChars(Int(UBound(arrChars) - LBound(arrChars) + 1) *
Rnd + LBound(arrChars))
tmp = tmp & tmpChar
Next
Password = tmp
End Function

When I run a query to reset all the passwords, all passwords get set to the
same password. How can I force the query to call the function uniquely for
each user?

Thanks;

Amy
 
Send a Dummy parameter that is a field

Function Password(passlength, DummyField) As String

Ken Snell explained it quite well

"If you do not include a field or fields as part of or as
the argument in a function called from a query, then Jet
will resolve the function's value just once and will not
call the function again. In other words, just once per
query, not once per record. This also is what happens if you
use a constant as an argument; again, the function is called
just once.

If you want a function to be called for each record, but the
function has no dependency on any field in the query, then
"fake" it by having the function accept an argument, but
have the function do nothing with the argument in its code.
Then use a field as the argument in the query."


Have an awesome day

Warm Regards,
Crystal

MVP Microsoft Access
strive4peace2006 at yahoo.com
 
You need to pass the contents of one of the Record Fields to the
Function - the Function can ignore the passed value - the Query
optimizer will then assume that the Function's result depends on the
value of the Field and will call it for each Record.

Define your function:

Function Password (Passlength As Integer, AnyField as Variant)
......

and reference it:

Password(12, AFieldName)

I've created a Password function that creates a random password

Function Password(passlength) As String
Dim i As Integer, tmp As String, tmpChar As String, arrChars(61) As
String, j As Integer
For i = 0 To 9
arrChars(j) = i
j = j + 1
Next
For i = 65 To 90
arrChars(j) = Chr(i)
j = j + 1
Next
For i = 97 To 122
arrChars(j) = Chr(i)
j = j + 1
Next
For i = 1 To passlength
Randomize
tmpChar = arrChars(Int(UBound(arrChars) - LBound(arrChars) + 1) *
Rnd + LBound(arrChars))
tmp = tmp & tmpChar
Next
Password = tmp
End Function

When I run a query to reset all the passwords, all passwords get set to the
same password. How can I force the query to call the function uniquely for
each user?

Thanks;

Amy

Please respond to the Newsgroup, so that others may benefit from the exchange.
Peter R. Fletcher
 
you're welcome, Amy ;) happy to help

Have an awesome day

Warm Regards,
Crystal

MVP Microsoft Access
strive4peace2006 at yahoo.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top