PC Review


Reply
Thread Tools Rate Thread

create module to insert random numbers

 
 
MackBlale
Guest
Posts: n/a
 
      31st Oct 2008
I have created a database to track employees for a military contract. I need
to create a field for a unique client ID number that is only filled in when I
click a button on the form "Assign Client ID" I want to create a module that
will generate a random number between 1 and 10,000, check the records to make
sure it does not already exist as a client id, and then insert the number
into the current record. If the number does already exist, I want to
continue generating numbers and checking until an unused number is found.
The numbers must be random and the employees will never number more than
10,000.
 
Reply With Quote
 
 
 
 
Scott Lichtenberg
Guest
Posts: n/a
 
      31st Oct 2008
Look at the Access RND function. To produce random integers in a given
range, use this formula:

Int((upperbound - lowerbound + 1) * Rnd + lowerbound)

You can set up a While Loop to generate the random number, check it against
your existing table, and regenerate it if necessary. Just as a side note,
this is probably not a good way to do things. If you have relatively few
employees, you should be OK, but as the number of employees grows, you are
going to generate more an more duplicate IDs. By the time you get up to
9000 records, it is going to take a whole lot of randomizations before you
get one that is available.

Another approach would be to set up a table with 10000 prenumbered records.
Generate a random number as above, go to that record in the table, then read
through the records sequentially to find the next unassigned record.

Hope this helps.


"MackBlale" <(E-Mail Removed)> wrote in message
news:B5099FAC-F9BA-4F44-A48E-(E-Mail Removed)...
>I have created a database to track employees for a military contract. I
>need
> to create a field for a unique client ID number that is only filled in
> when I
> click a button on the form "Assign Client ID" I want to create a module
> that
> will generate a random number between 1 and 10,000, check the records to
> make
> sure it does not already exist as a client id, and then insert the number
> into the current record. If the number does already exist, I want to
> continue generating numbers and checking until an unused number is found.
> The numbers must be random and the employees will never number more than
> 10,000.


 
Reply With Quote
 
MackBlale
Guest
Posts: n/a
 
      31st Oct 2008
Scott,
Initially I used the RND function on table properties to define the data
with a no randoms allowed. The database would lock up when a random number
was generated. There will probably never be more than 1500 clients, that I
am sure of.
10,000 is the number to make sure I have less of a chance of getting the
same number. I tried the 10000 number in a table method and it is way too
cumbersome for me to work. I need for Access to generate the number for a
single record on demand, make sure it hasn't been assigned, and place it in
the current record. I simply need the code to do it because I really don't
understand the modules or macros in Access.

"Scott Lichtenberg" wrote:

> Look at the Access RND function. To produce random integers in a given
> range, use this formula:
>
> Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
>
> You can set up a While Loop to generate the random number, check it against
> your existing table, and regenerate it if necessary. Just as a side note,
> this is probably not a good way to do things. If you have relatively few
> employees, you should be OK, but as the number of employees grows, you are
> going to generate more an more duplicate IDs. By the time you get up to
> 9000 records, it is going to take a whole lot of randomizations before you
> get one that is available.
>
> Another approach would be to set up a table with 10000 prenumbered records.
> Generate a random number as above, go to that record in the table, then read
> through the records sequentially to find the next unassigned record.
>
> Hope this helps.
>
>
> "MackBlale" <(E-Mail Removed)> wrote in message
> news:B5099FAC-F9BA-4F44-A48E-(E-Mail Removed)...
> >I have created a database to track employees for a military contract. I
> >need
> > to create a field for a unique client ID number that is only filled in
> > when I
> > click a button on the form "Assign Client ID" I want to create a module
> > that
> > will generate a random number between 1 and 10,000, check the records to
> > make
> > sure it does not already exist as a client id, and then insert the number
> > into the current record. If the number does already exist, I want to
> > continue generating numbers and checking until an unused number is found.
> > The numbers must be random and the employees will never number more than
> > 10,000.

>
>

 
Reply With Quote
 
Jeff Boyce
Guest
Posts: n/a
 
      31st Oct 2008
You've outlined some very specific constraints on the creation of a unique
row ID.

Why? What will having a "random" unique row ID allow you to do that you
couldn't do otherwise?

Regards

Jeff Boyce
Microsoft Office/Access MVP

"MackBlale" <(E-Mail Removed)> wrote in message
news:3E6F547E-E556-416E-807E-(E-Mail Removed)...
> Scott,
> Initially I used the RND function on table properties to define the data
> with a no randoms allowed. The database would lock up when a random
> number
> was generated. There will probably never be more than 1500 clients, that
> I
> am sure of.
> 10,000 is the number to make sure I have less of a chance of getting the
> same number. I tried the 10000 number in a table method and it is way too
> cumbersome for me to work. I need for Access to generate the number for a
> single record on demand, make sure it hasn't been assigned, and place it
> in
> the current record. I simply need the code to do it because I really
> don't
> understand the modules or macros in Access.
>
> "Scott Lichtenberg" wrote:
>
>> Look at the Access RND function. To produce random integers in a given
>> range, use this formula:
>>
>> Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
>>
>> You can set up a While Loop to generate the random number, check it
>> against
>> your existing table, and regenerate it if necessary. Just as a side
>> note,
>> this is probably not a good way to do things. If you have relatively few
>> employees, you should be OK, but as the number of employees grows, you
>> are
>> going to generate more an more duplicate IDs. By the time you get up to
>> 9000 records, it is going to take a whole lot of randomizations before
>> you
>> get one that is available.
>>
>> Another approach would be to set up a table with 10000 prenumbered
>> records.
>> Generate a random number as above, go to that record in the table, then
>> read
>> through the records sequentially to find the next unassigned record.
>>
>> Hope this helps.
>>
>>
>> "MackBlale" <(E-Mail Removed)> wrote in message
>> news:B5099FAC-F9BA-4F44-A48E-(E-Mail Removed)...
>> >I have created a database to track employees for a military contract. I
>> >need
>> > to create a field for a unique client ID number that is only filled in
>> > when I
>> > click a button on the form "Assign Client ID" I want to create a
>> > module
>> > that
>> > will generate a random number between 1 and 10,000, check the records
>> > to
>> > make
>> > sure it does not already exist as a client id, and then insert the
>> > number
>> > into the current record. If the number does already exist, I want to
>> > continue generating numbers and checking until an unused number is
>> > found.
>> > The numbers must be random and the employees will never number more
>> > than
>> > 10,000.

>>
>>



 
Reply With Quote
 
MackBlale
Guest
Posts: n/a
 
      1st Nov 2008
The employees I am dealing with are contracted to gather human intelligence
in Iraq. I must have a unique ID for each individual that is non-sequential
to prevserve the true identity of the person from those who don't need to
know. I have 52 different locations and sequential numbers can be traced
back to a single user. My employee pool is around 500 but will never be more
than 1500. 10,000 random numbers to choose from should be adequate. How do
I do it?
Thanks

"Jeff Boyce" wrote:

> You've outlined some very specific constraints on the creation of a unique
> row ID.
>
> Why? What will having a "random" unique row ID allow you to do that you
> couldn't do otherwise?
>
> Regards
>
> Jeff Boyce
> Microsoft Office/Access MVP
>
> "MackBlale" <(E-Mail Removed)> wrote in message
> news:3E6F547E-E556-416E-807E-(E-Mail Removed)...
> > Scott,
> > Initially I used the RND function on table properties to define the data
> > with a no randoms allowed. The database would lock up when a random
> > number
> > was generated. There will probably never be more than 1500 clients, that
> > I
> > am sure of.
> > 10,000 is the number to make sure I have less of a chance of getting the
> > same number. I tried the 10000 number in a table method and it is way too
> > cumbersome for me to work. I need for Access to generate the number for a
> > single record on demand, make sure it hasn't been assigned, and place it
> > in
> > the current record. I simply need the code to do it because I really
> > don't
> > understand the modules or macros in Access.
> >
> > "Scott Lichtenberg" wrote:
> >
> >> Look at the Access RND function. To produce random integers in a given
> >> range, use this formula:
> >>
> >> Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
> >>
> >> You can set up a While Loop to generate the random number, check it
> >> against
> >> your existing table, and regenerate it if necessary. Just as a side
> >> note,
> >> this is probably not a good way to do things. If you have relatively few
> >> employees, you should be OK, but as the number of employees grows, you
> >> are
> >> going to generate more an more duplicate IDs. By the time you get up to
> >> 9000 records, it is going to take a whole lot of randomizations before
> >> you
> >> get one that is available.
> >>
> >> Another approach would be to set up a table with 10000 prenumbered
> >> records.
> >> Generate a random number as above, go to that record in the table, then
> >> read
> >> through the records sequentially to find the next unassigned record.
> >>
> >> Hope this helps.
> >>
> >>
> >> "MackBlale" <(E-Mail Removed)> wrote in message
> >> news:B5099FAC-F9BA-4F44-A48E-(E-Mail Removed)...
> >> >I have created a database to track employees for a military contract. I
> >> >need
> >> > to create a field for a unique client ID number that is only filled in
> >> > when I
> >> > click a button on the form "Assign Client ID" I want to create a
> >> > module
> >> > that
> >> > will generate a random number between 1 and 10,000, check the records
> >> > to
> >> > make
> >> > sure it does not already exist as a client id, and then insert the
> >> > number
> >> > into the current record. If the number does already exist, I want to
> >> > continue generating numbers and checking until an unused number is
> >> > found.
> >> > The numbers must be random and the employees will never number more
> >> > than
> >> > 10,000.
> >>
> >>

>
>
>

 
Reply With Quote
 
Jeff Boyce
Guest
Posts: n/a
 
      3rd Nov 2008
Use your favorite on-line search engine. Enter:
ms access random number generator

You should get a lot of 'hits'. Use the technique that works best in your
situation.

Regards

Jeff Boyce
Microsoft Office/Access MVP




"MackBlale" <(E-Mail Removed)> wrote in message
news091B3BF-FCCF-4589-AD63-(E-Mail Removed)...
> The employees I am dealing with are contracted to gather human
> intelligence
> in Iraq. I must have a unique ID for each individual that is
> non-sequential
> to prevserve the true identity of the person from those who don't need to
> know. I have 52 different locations and sequential numbers can be traced
> back to a single user. My employee pool is around 500 but will never be
> more
> than 1500. 10,000 random numbers to choose from should be adequate. How
> do
> I do it?
> Thanks
>
> "Jeff Boyce" wrote:
>
>> You've outlined some very specific constraints on the creation of a
>> unique
>> row ID.
>>
>> Why? What will having a "random" unique row ID allow you to do that you
>> couldn't do otherwise?
>>
>> Regards
>>
>> Jeff Boyce
>> Microsoft Office/Access MVP
>>
>> "MackBlale" <(E-Mail Removed)> wrote in message
>> news:3E6F547E-E556-416E-807E-(E-Mail Removed)...
>> > Scott,
>> > Initially I used the RND function on table properties to define the
>> > data
>> > with a no randoms allowed. The database would lock up when a random
>> > number
>> > was generated. There will probably never be more than 1500 clients,
>> > that
>> > I
>> > am sure of.
>> > 10,000 is the number to make sure I have less of a chance of getting
>> > the
>> > same number. I tried the 10000 number in a table method and it is way
>> > too
>> > cumbersome for me to work. I need for Access to generate the number
>> > for a
>> > single record on demand, make sure it hasn't been assigned, and place
>> > it
>> > in
>> > the current record. I simply need the code to do it because I really
>> > don't
>> > understand the modules or macros in Access.
>> >
>> > "Scott Lichtenberg" wrote:
>> >
>> >> Look at the Access RND function. To produce random integers in a
>> >> given
>> >> range, use this formula:
>> >>
>> >> Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
>> >>
>> >> You can set up a While Loop to generate the random number, check it
>> >> against
>> >> your existing table, and regenerate it if necessary. Just as a side
>> >> note,
>> >> this is probably not a good way to do things. If you have relatively
>> >> few
>> >> employees, you should be OK, but as the number of employees grows, you
>> >> are
>> >> going to generate more an more duplicate IDs. By the time you get up
>> >> to
>> >> 9000 records, it is going to take a whole lot of randomizations before
>> >> you
>> >> get one that is available.
>> >>
>> >> Another approach would be to set up a table with 10000 prenumbered
>> >> records.
>> >> Generate a random number as above, go to that record in the table,
>> >> then
>> >> read
>> >> through the records sequentially to find the next unassigned record.
>> >>
>> >> Hope this helps.
>> >>
>> >>
>> >> "MackBlale" <(E-Mail Removed)> wrote in message
>> >> news:B5099FAC-F9BA-4F44-A48E-(E-Mail Removed)...
>> >> >I have created a database to track employees for a military contract.
>> >> >I
>> >> >need
>> >> > to create a field for a unique client ID number that is only filled
>> >> > in
>> >> > when I
>> >> > click a button on the form "Assign Client ID" I want to create a
>> >> > module
>> >> > that
>> >> > will generate a random number between 1 and 10,000, check the
>> >> > records
>> >> > to
>> >> > make
>> >> > sure it does not already exist as a client id, and then insert the
>> >> > number
>> >> > into the current record. If the number does already exist, I want
>> >> > to
>> >> > continue generating numbers and checking until an unused number is
>> >> > found.
>> >> > The numbers must be random and the employees will never number more
>> >> > than
>> >> > 10,000.
>> >>
>> >>

>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to? Create random letters and numbers in a cell Chris Microsoft Excel Worksheet Functions 3 5th Jun 2008 08:04 AM
how do i insert numbers from Random list (1-60) without repeating =?Utf-8?B?b2N0ZXQ=?= Microsoft Excel Misc 1 6th Jun 2006 07:31 AM
insert combination of random letters and numbers - an example aztecbrainsurgeon@yahoo.com Microsoft Excel Programming 0 4th Apr 2006 12:18 AM
VBA module/function to generate random numbers with specified mean and SD Robert Reid Microsoft Excel Programming 6 27th Sep 2005 01:33 AM
create random NON-REPEATING numbers (e.g., 20 #'s between 1-100) =?Utf-8?B?TGVvbg==?= Microsoft Excel Misc 1 3rd Jun 2005 12:20 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:33 AM.