Update Query Returns Same Password

G

Guest

Below is my function and SQL command. The function works great except that I'm trying to generate about 300 random passwords via an update query. This function and SQL command give every record the same password. If someone could please tell me how to tweak this so that I can generate 300 different passwords I would greatly appreaciate it

Thanks

Joh

Function

Function RandomPassword(
Dim intRandom As Intege
Dim strPassword As Strin
Randomize Time
Do Until Len(strPassword) =
intRandom = Int(Rnd(1) * 75) + 4
Select Case intRando
Case 48 To 57, 65 To 90, 97 To 12
strPassword = strPassword & Chr$(intRandom
End Selec
Loo
RandomPassword = strPasswor
End Functio

SQL

UPDATE web SET web.[Password] = RandomPassword();
 
S

Sandra Daigle

Hi John,

Try modifying your function to accept a value from one of the columns in
your table - it doesn't have to use the value. This ensures that the
function gets called for every row in the query - otherwise, it only gets
called once.

This is easily verified by putting a debug.print statement into the
function - you'll see that it only prints once with the query as you have
it. For my test, I added a numeric field as the argument. The parameter,
inti, isn't used in the function.

Function RandomPassword(inti As Integer)
Dim intRandom As Integer
Dim strPassword As String
Randomize Timer

Do Until Len(strPassword) = 8
intRandom = Int(Rnd(1) * 75) + 47
Select Case intRandom
Case 48 To 57, 65 To 90, 97 To 122
strPassword = strPassword & Chr$(intRandom)
End Select
Loop
Debug.Print strPassword
RandomPassword = strPassword
End Function

SQL
 
G

Guest

Thanks so much Sandra! Worked like a charm

----- Sandra Daigle wrote: ----

Hi John

Try modifying your function to accept a value from one of the columns i
your table - it doesn't have to use the value. This ensures that th
function gets called for every row in the query - otherwise, it only get
called once

This is easily verified by putting a debug.print statement into th
function - you'll see that it only prints once with the query as you hav
it. For my test, I added a numeric field as the argument. The parameter
inti, isn't used in the function

Function RandomPassword(inti As Integer
Dim intRandom As Intege
Dim strPassword As Strin
Randomize Time

Do Until Len(strPassword) =
intRandom = Int(Rnd(1) * 75) + 4
Select Case intRando
Case 48 To 57, 65 To 90, 97 To 12
strPassword = strPassword & Chr$(intRandom
End Selec
Loo
Debug.Print strPasswor
RandomPassword = strPasswor
End Functio

SQ
-------
UPDATE web SET web.[Password] = RandomPassword(id)

--
Sandra Daigl
[Microsoft Access MVP
For the benefit of others please post all replies to this newsgroup

John wrote
Below is my function and SQL command. The function works great excep
that I'm trying to generate about 300 random passwords via an updat
query. This function and SQL command give every record the sam
password. If someone could please tell me how to tweak this so that
can generate 300 different passwords I would greatly appreaciate it
Thanks
Joh
Function
Function RandomPassword(
Dim intRandom As Intege
Dim strPassword As Strin
Randomize Time
Do Until Len(strPassword) =
intRandom = Int(Rnd(1) * 75) + 4
Select Case intRando
Case 48 To 57, 65 To 90, 97 To 12
strPassword = strPassword & Chr$(intRandom
End Selec
Loo
RandomPassword = strPasswor
End Functio
SQL
UPDATE web SET web.[Password] = RandomPassword()
 
S

Sandra Daigle

Glad to hear it :)

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.
Thanks so much Sandra! Worked like a charm.

----- Sandra Daigle wrote: -----

Hi John,

Try modifying your function to accept a value from one of the
columns in your table - it doesn't have to use the value. This
ensures that the function gets called for every row in the query -
otherwise, it only gets called once.

This is easily verified by putting a debug.print statement into the
function - you'll see that it only prints once with the query as you
have it. For my test, I added a numeric field as the argument. The
parameter, inti, isn't used in the function.

Function RandomPassword(inti As Integer)
Dim intRandom As Integer
Dim strPassword As String
Randomize Timer

Do Until Len(strPassword) = 8
intRandom = Int(Rnd(1) * 75) + 47
Select Case intRandom
Case 48 To 57, 65 To 90, 97 To 122
strPassword = strPassword & Chr$(intRandom)
End Select
Loop
Debug.Print strPassword
RandomPassword = strPassword
End Function

SQL
--------
UPDATE web SET web.[Password] = RandomPassword(id);

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.
Below is my function and SQL command. The function works great
except > that I'm trying to generate about 300 random passwords via
an update > query. This function and SQL command give every record
the same > password. If someone could please tell me how to tweak
this so that I > can generate 300 different passwords I would
greatly appreaciate it. >> Thanks!
John
Function:
Function RandomPassword()
Dim intRandom As Integer
Dim strPassword As String
Randomize Timer
Do Until Len(strPassword) = 8
intRandom = Int(Rnd(1) * 75) + 47
Select Case intRandom
Case 48 To 57, 65 To 90, 97 To 122
strPassword = strPassword & Chr$(intRandom)
End Select
Loop
RandomPassword = strPassword
End Function
SQL:
UPDATE web SET web.[Password] = RandomPassword();
 
C

Chris Nebinger

Sandra,

I usually don't call functions from my queries, so I did
not know that. I guess i learned my item for the day.
I'm going home :)


Chris

-----Original Message-----
Glad to hear it :)

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.
Thanks so much Sandra! Worked like a charm.

----- Sandra Daigle wrote: -----

Hi John,

Try modifying your function to accept a value from one of the
columns in your table - it doesn't have to use the value. This
ensures that the function gets called for every row in the query -
otherwise, it only gets called once.

This is easily verified by putting a debug.print statement into the
function - you'll see that it only prints once with the query as you
have it. For my test, I added a numeric field as the argument. The
parameter, inti, isn't used in the function.

Function RandomPassword(inti As Integer)
Dim intRandom As Integer
Dim strPassword As String
Randomize Timer

Do Until Len(strPassword) = 8
intRandom = Int(Rnd(1) * 75) + 47
Select Case intRandom
Case 48 To 57, 65 To 90, 97 To 122
strPassword = strPassword & Chr$(intRandom)
End Select
Loop
Debug.Print strPassword
RandomPassword = strPassword
End Function

SQL
--------
UPDATE web SET web.[Password] = RandomPassword(id);

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.
Below is my function and SQL command. The
function works great
except > that I'm trying to generate about 300 random passwords via
an update > query. This function and SQL command give every record
the same > password. If someone could please tell me how to tweak
this so that I > can generate 300 different passwords I would
greatly appreaciate it. >> Thanks!
John
Function:
Function RandomPassword()
Dim intRandom As Integer
Dim strPassword As String
Randomize Timer
Do Until Len(strPassword) = 8
intRandom = Int(Rnd(1) * 75) + 47
Select Case intRandom
Case 48 To 57, 65 To 90, 97 To 122
strPassword = strPassword & Chr$(intRandom)
End Select
Loop
RandomPassword = strPassword
End Function
SQL:
UPDATE web SET web.[Password] = RandomPassword
();
.
 

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

Top