473,785 Members | 2,553 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4799
On 28 Mar 2005 00:05:36 -0800, "ironcito" <co****@ironcit o.com> wrote:
Hello!

I'm looking for a way to have a field in my database that will
automaticall y 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) = RandomAlphaNumC har()
Next

AlphaNumString = strResult
End Function

Public function RandomAlphaNumC har() As String
Dim lngBase36Num As Long

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

If lngBase36Num < 10 Then
RandomAlphaNumC har = Str(lngBase36Nu m)
Else
RandomAlphaNumC har = 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****@ironcit o.com> wrote in message
news:11******** *************@g 14g2000cwa.goog legroups.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 MyRandomFourCha racters as string
This is the call:
MyRandomFourCha racters = AlphaNumString( 4)

You can also return any number of random characters using the function
given to you.
Dim MyRandomTenChar acters as string
MyRandomTenChar acters = 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
7290
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? STL set, map? Could you give me a little code example? Thank you.
4
2210
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 nos(RandomID)stored in the combobox control. Everytime I enter a new record in F1, the next available RandomID should be automatically assigned to the new record entry and displayed in the respective form control(F2). Can anybody guide me...
3
2221
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 appreciate any help!!! Thank you
7
8811
by: Fernando Rodríguez | last post by:
Hi, How can I know if a string only has alfanumeric chars? Thanks
0
2026
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 reasons. With textboxes I'm doing this with a RegularExpressionValidator control and have the following the following attribute setup: ValidationExpression="^{6,100}" This limits the user input to alphanumeric characters as well of some selected...
14
4753
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
18142
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 random does not mean that its unique.
5
8377
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 number for a project I am working on. But I am unsatisfied with the results I am getting. Here is my current method, it works but like I said there has to be a better way of doing it. public static String plate() { int x = 6; char plate...
15
52633
by: bitshift | last post by:
Anyone got an example ?
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10090
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9949
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5380
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.