473,320 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Random alphanumeric string

Hello!

I'm looking for a way to have a field in my database that will
automatically be filled with a random 4-character alphanumeric string
every time I enter a new record. Like an autonumber field, but
alphanumeric and random. Could anyone tell me how to do this? Please
explain it so that a newbie can do it. Thanks a lot, and have a nice
day! =)

Nov 13 '05 #1
6 4757
On 28 Mar 2005 00:05:36 -0800, "ironcito" <co****@ironcito.com> wrote:
Hello!

I'm looking for a way to have a field in my database that will
automatically be filled with a random 4-character alphanumeric string
every time I enter a new record. Like an autonumber field, but
alphanumeric and random. Could anyone tell me how to do this? Please
explain it so that a newbie can do it. Thanks a lot, and have a nice
day! =)


Something like this, perhaps? This is untested, so it might need some
debugging.

Public function Random AlphaNumString(StringLen As Long) As String
Dim lngCharNum As Long
Dim strResult as String

strResult = Space(StringLen)
For lngCharNum = 1 to StringLen
Mid$(StringLen, lngCharNum, 1) = RandomAlphaNumChar()
Next

AlphaNumString = strResult
End Function

Public function RandomAlphaNumChar() As String
Dim lngBase36Num As Long

Randomize
lngBase36Num = Int(Rnd(1)*36)

If lngBase36Num < 10 Then
RandomAlphaNumChar = Str(lngBase36Num)
Else
RandomAlphaNumChar = Chr(Asc("A") + lngBase36Num - 10)
Endif

End Function
Nov 13 '05 #2
Hi, and thanks for your answer. You must excuse my ignorance, but where
should I enter all that? =/
Thanks again.

Nov 13 '05 #3
Ironcito,
If you can click on the Modules tab of the database window of an Access
database and the New | Module button works, then add a new Module to your
database and type all that there.

"ironcito" <co****@ironcito.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
Hi, and thanks for your answer. You must excuse my ignorance, but where
should I enter all that? =/
Thanks again.

Nov 13 '05 #4
OK I've added the module! (Should I remove "Option compare database"
from the begining?) Now what do I do with the module, so as to
accomplish my initial objective? Thanks a lot.

Nov 13 '05 #5
ironcito wrote:
OK I've added the module! (Should I remove "Option compare database"
from the begining?) Now what do I do with the module, so as to
accomplish my initial objective? Thanks a lot.


Now that you have the function in a module, you can call it from any
place in your application... such as a form or query or report or
another subroutine in a module section. Remember functions return an
answer so you need to define a string to hold the answer.

Dim MyRandomFourCharacters as string
This is the call:
MyRandomFourCharacters = AlphaNumString(4)

You can also return any number of random characters using the function
given to you.
Dim MyRandomTenCharacters as string
MyRandomTenCharacters = AlphaNumString(10)

You should read help or purchase a book on Access.

Ron

--
Ronald W. Roberts
Roberts Communication
rw*@robcom.com

Nov 13 '05 #6
Hi!

You must excuse me for my ignorance and persistency, but I'm not
experienced with functions and I do not work much with Access regularly
so as to justify learning everything. Just a final question, once I
have created a module, how do I call it? Suppose I want to create a
form that will automatically fill the field with the 4-character
alphanumeric string everytime I create a new record, but not create a
new string if I edit one... what do I type and where? Thanks! =)

Nov 13 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: eric.gagnon | last post by:
In a program randomly generating 10 000 000 alphanumeric codes of 16 characters in length (Ex.: "ZAZAZAZAZAZAZ156"), what would be an efficient way to ensure that I do not generate duplicates? ...
4
by: anita | last post by:
I had posted this question before, but did not hear from anybody. Can somebody pls help me out. I am creating a table with two fields F1, F2 and F2 has about 50,000 randomly generated alphanumeric...
3
by: aahmad76 | last post by:
Can anyone please help me. I am trying to desing a program that will create a 10 digit alphanumeric password. I am new to the Vb.net environment, and sometimes have no idea what to do. I...
7
by: Fernando Rodríguez | last post by:
Hi, How can I know if a string only has alfanumeric chars? Thanks
0
by: =?Utf-8?B?am1obWFpbmU=?= | last post by:
I'm trying to create a process that allows me to limit the non-alphanumeric characters generated with the PasswordRecovery control. Specially I want to suppress some characters for security...
14
by: avanti | last post by:
Hi, I need to generate random alphanumeric password strings for the users in my application using Javascript. Are there any links that will have pointers on the same? Thanks, Avanti
9
by: Robert Mago | last post by:
Is there a way to create a 10 characthers or less, alph-numeric string which is unique. I can't use the guid since its longer then 10 characthers. Also i cannot use a random number, since being...
5
by: dav3 | last post by:
Howdy folks, was wondering if anyone could assist me in a better method for generating a alphanumeric sequence of 6 characters/digits. The method I am currently using gives me a random license plate...
15
by: bitshift | last post by:
Anyone got an example ?
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.