Best way to generate a unique random serial number

acura123

Board Regular
Joined
Jul 13, 2003
Messages
87
What is the best way to produce a random non repeating serial numbers in access. I was told using autonumber is not the way to go, and besides it produces negative numbers.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
using the RANDOMIZE statement in code ?
 
Upvote 0
maybe use the sequential autonumber? What that does is with new records, it uses all positive numbers, but they are all unique. They continue to be unique too, within the same recordset, even if previous records are deleted out (that held previous autonumber values). Use the INCREMENTAL option when you make the table.
 
Upvote 0
Is there a problem with generating negative numbers? Surely, the actual number generated should be irrelevant as long as it's unique. It's important to remember that primary keys need to be unique, but in most cases it doesn't matter what the key value is. For most of the databases I build, the primary key is never displayed.

Possible exceptions would be a Social Security ID or an ISBN, where the values are text, must be entered by the user, and are meant to be unique by definition.

Denis
 
Upvote 0
I'm trying to create random account numbers and was told not to use the auto number as a means to do it.

I was told the best way was to use a random number and I guess check it against a table.

Is this the correct way to create a positive non duplicative number like a serial number or account number? And if so how do you check it against a table?
 
Upvote 0
Why were you told not to use Autonumber? I'm trying to understand the logic before you find yourself painted into a corner for no good reason.

Also, are you sure that you will never generated more than 999 accounts?

The answer is, yes you can do this. It involves a bit of code to check that the number is unique, and a loop to generate another if it isn't. But I wonder if you actually need the mechanism before you go to the trouble.

Denis
 
Upvote 0
When I assign the account number I don't want the account to appear as -2746785
but rather account#7648477.

But I don't want a duplicate account number.
 
Upvote 0
When I assign the account number I don't want the account to appear as -2746785
but rather account#7648477.

But I don't want a duplicate account number.
see my last statement acura. This should NOT be difficult. You are going to have to put up with the negative autonumber if you are using it in the RANDOM sense instead of the INCREMENTAL sense (option). It's just the way it is...from what I can understand anyway. You can use code to turn any negatives into positives, but then you would have to check to see if that number is still in the recordset at the time you make the new record. Why not just use the incremental option for the autonumber? This will guarantee you the uniqueness. Are the numbers not enough digits long? Just trying to help you out...this seems to have gotten way more complicated than it should be.
 
Upvote 0

Forum statistics

Threads
1,214,622
Messages
6,120,580
Members
448,972
Latest member
Shantanu2024

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top