473,659 Members | 2,662 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Assign randon number to all records in one field

I need to assign a different random number to each record in one
column in one table in access. How can i do this?

Oct 3 '07 #1
2 5589
ARC
That's a strange one!

That's an odd one. Only way I know of to do this would be with code. Say
your column in the table is called RandNumb, then you would need to open the
table recordset (and open another recordset of the same table for searches)
via code, start at the first record, and use a random function in each loop
to generate a random number. Then before you update the line, do a loop
where you search existing values in the RandNumb column, and keep generating
/ searching until it comes up with a unique random number, then write it.
Keep going until the end of recordset:

Sorry in advance, I just wrote this in this window, so didn't have time to
test. And the code's a bit orthodox, as I'm not using a second do / loop for
the random #. Anyway, it's the basic structure, just may need some
de-bugging. Hope this helps.
Dim db as database, rs as recordset, IntRandNum as integer, TopRandNum as
long
set db=currentDb()
set rs =db.openrecords et("<tblname>", db_open_dynaset )
set rs2=db.openreco rdset("<tblname >",db_open_snap shot) 'snapshot. rs2
will be search only
TopRandNum=1000 00 'set the max random number you would want
rs.movefirst
do until rs.eof
IntRandNum = Int((TopRandNum Val * Rnd) + 1)
contin:
rs2.findfirst "RandNumb = " & IntRandNum
if rs2.nomatch then
rs.edit
rs!RandNumb = IntRandNum
rs.update
else
IntRandNum = Int((TopRandNum Val * Rnd) + 1)
goto contin
end if
rs.movenext
loop
rs2.close
rs.close
set db = nothing
<ar****@yahoo.c omwrote in message
news:11******** **************@ 50g2000hsm.goog legroups.com...
>I need to assign a different random number to each record in one
column in one table in access. How can i do this?
Oct 3 '07 #2
You can do it with an update query using the RND() function.
Note: in the example I force it to eval with each record by referencing a
field in the table. You will also need to call Randomize() sometime before
running the query.

SELECT Rnd(IIf([Qty]<>0,1,1)) AS Expr1
FROM tblParts;

<ar****@yahoo.c omwrote in message
news:11******** **************@ 50g2000hsm.goog legroups.com...
I need to assign a different random number to each record in one
column in one table in access. How can i do this?

Oct 3 '07 #3

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

Similar topics

1
2635
by: Bryan Zash | last post by:
When querying a bit field, I am encountering a problem with MS SQL Server returning a larger number of records for a table than the actual number of records that exist within that table. For example, my customer table has 1 million unique records, so the results of the following query are as such: select count(customer_nbr) from customer = 1,000,000 There is bit field in the customer table that denotes whether a
2
2478
by: news.cablevision.qc.ca | last post by:
Hi! I want, using a form, enter a number and then, read that number of records in a database and store information in variables. The only way I see to do this is to do a FOR...NEXT to the number entered in the form, and then include the database reading into it. THE PROBLEM: <%
14
12031
by: amywolfie | last post by:
Hi All: I know this is simple, but I just can't seem to get there: I need to sort a table by a text field (txtDescription), then assign sequential numbers to the field SEQUENCE in table. Every time a new record is added, the all SEQUENCE #'s must be reset. The re-numbering will be triggered by an EXPORT button.
2
2285
by: Megan | last post by:
Hi everybody- I have 2 tables, Hearings and Rulings. Both have primary keys called, CaseID, that are autonumbers. I don't want both tables to have the same autonumber. For example, if Hearings has 55, then I want Rulings to have a number greater than 55. Two or more Hearings may be entered before a Ruling is entered. For example, Hearings with CaseIDs= 55, 56, and 57 may be entered before a Ruling or vice versa. There is no definite...
7
7235
by: astro | last post by:
Anyone have suggestions on where to troubleshoot this error? Background: -Access 2k v. 9.0.6926 sp3 - front and backend on production server (wiindows 2k) -accessed via Citrix -front-end is mde, backend is mdb -only occurs on the production server -only occurs with mde verson - i've tested the problem with the mdb version of the front-end and it loads/generates the document fine on the production
2
15711
by: dskillingstad | last post by:
I'm trying to assign a custom value to a textbox. Here's what I have. I've created a module and "default value" code for a textbox which generates a custom auto-number (yyyy-0000) when a New Record button is clicked. The code checks the table for the highest value and then assigns 1 and inserts the value. I have a second text box which needs the same type of custom auto-number which has to be generated from a second command button. ...
7
3078
by: john | last post by:
I have a form with 1 table. I would like to create a field in my form that shows the number of records (of the whole table) that have one particular value. Is that possible? I fiddled with a calculated field but I couldn't make it work. Thanks in advance, john
15
1778
by: Hexman | last post by:
Hello All, How do I limit the number of detail records selected in a Master-Detail set using SQL? I want to select all master records for a date, but only the first 3 records for the details (based on the primary key of the detail record). I've been trying with "TOP 3", but can't get anywhere. Using Access 2000. Something like: SELECT t1.*, TOP 3 t2.*
3
2509
by: Bjesparz | last post by:
I need to assign a new, sequential, Work Order number inside the WO# field of my Orders table. I also want to to have control over the number assignment using a double click button in the Order form. (Note: I'll use the same process to assign an Invoice number as well. I want control over the numbers because not all entries will require a Work Order number. (By the way all records are tracked with an AutoNumber) I have a table called...
0
8427
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
8330
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8746
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
8523
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
7355
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4334
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2749
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
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
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.