Generating random text and numbers in a field

A

Andrew Turner

I am asking this question again since I think last time it was not clear
what I was doing so got some useful suggestions, but none that worked.

I am using an Access database as a backend for a web site. I have users
create their own accounts, putting in name, address, email etc via a web
form which then inserts the data in the Access database backend.

I do not want them to choose their own password, I want the password data in
the database to be automatically created when the record is added. Therefore
I have created a field in a table in the database called 'password'. I now
just need to know what I can set the default to in this field in order that
a random set of letters and numbers can be generated in the field.

Can anyone give me a simple answer, or at least tell me that I am trying to
do something that is not possible.

Many thanks
Andrew Turner
 
R

Roger Carlson

Here's a small function that will create a random password of a specified
length.

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

'*** used with the RND() function to return
' a random number
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
 
D

Douglas J. Steele

The only option is to write a function in VBA that generates the password
and then store that password in the appropriate field. There is nothing
built into Access that would let you set a default value to accomplish this.
 
T

Tom van Stiphout

On Thu, 25 Oct 2007 13:03:59 +0200, "Andrew Turner"

There is a simple way if it's OK for the password to have numbers
only: make the column an AutoNumber, and set NewValues property to
Random.

Beyond that, you'll need to write some script in your web page to
create a random password. You didn't mention what development tool
you're using, but there likely is a newsgroup for it.

-Tom.
 

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