You must create an Event Procedure, and call the function in that procedure.
The function Arvin gave you cannot be used as an event.
--
Doug Steele, Microsoft Access MVP
(No private e-mails, please)
from the button OnClick event I have fGenRandomString.
Antonio
:
How are you calling the function?
The way Arvin wrote it, you must pass the number of characters you want
in
the string:
For instance, fGenRandomString(8) will return an 8 character string.
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
Arvin,
Everytime I try to reference to the function, I get an "Argument not
Optional" error message. I created a module and I am trying to call
it
from
a cmdbutton. Thanks, Antonio
:
Hello, everyone...I just thought of something to implement in my
database...How could I have the database auto-generate a username
and
password? Of course there can't be duplicates. I have a username
and
password field that are assigned to customers subscribing to
online
products.
Any ideas? Thanks
Here's some code that will generate a password. Just enter the
number of
characters you want. It includes "special characters" and a space,
so
make
sure your system will handle them, or remove them from the list:
Public Function fGenRandomString(intCharCount As Integer) As String
Dim i As Integer
Dim intPos As Integer
Dim strOut As String
Dim strOne As String * 1
Dim strCharPool As String
Const strChars =
"abcdegghijklmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ123456789~
@!#$%^&*()+{}]["
strCharPool = strChars
strOut = ""
If Not intCharCount > Len(strChars) Then
Randomize
For i = 1 To intCharCount
intPos = Int(Len(strCharPool) * Rnd + 1)
strOne = Mid(strCharPool, intPos, 1)
strCharPool = Left(strCharPool, intPos - 1) &
Mid(strCharPool,
intPos + 1)
strOut = strOut & strOne
Next
Else
strOut = "Too Long"
End If
fGenRandomString = strOut
End Function
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access