Random Number in Query

Hi.  I am trying to get a Random number between 0 and 5 to appear on each row 
of a query.  I can get the same number on each row (it changes every time I 
run the query) but cannot get a different random number for each row.

Basically, I want to create some Test data by adding the Random number to a 
Received Date and then saving this new date as a Completed Date.

I have created a Module to generate a Random number:

Function Random_Number() As Integer

    Randomize
    Random_Number = Int(Rnd * 6)

End Function


Then, I call the function from a query:

Field = Number: Random_Number()

Can anyone tell me what I am doing wrong?

Cheers,
Steve.

0
Utf
1/3/2008 10:51:01 AM
access.queries 6343 articles. 1 followers. Follow

2 Replies
1708 Views

Similar Articles

[PageSpeed] 39

Sorry, Ive just answered my own question!!

I used my Unique ID field in the Rnd command:

RandomNumber : Int(Rnd([Workflow_Ref])*6)

And that gives me a value between 0 and 5 for adding onto my Received date.

Thanks Me :)



"FBxiii" wrote:

> Hi.  I am trying to get a Random number between 0 and 5 to appear on each row 
> of a query.  I can get the same number on each row (it changes every time I 
> run the query) but cannot get a different random number for each row.
> 
> Basically, I want to create some Test data by adding the Random number to a 
> Received Date and then saving this new date as a Completed Date.
> 
> I have created a Module to generate a Random number:
> 
> Function Random_Number() As Integer
> 
>     Randomize
>     Random_Number = Int(Rnd * 6)
> 
> End Function
> 
> 
> Then, I call the function from a query:
> 
> Field = Number: Random_Number()
> 
> Can anyone tell me what I am doing wrong?
> 
> Cheers,
> Steve.
> 
0
Utf
1/3/2008 11:00:01 AM
hi Steve,

FBxiii wrote:
> Hi.  I am trying to get a Random number between 0 and 5 to appear on each row 
> of a query.  I can get the same number on each row (it changes every time I 
> run the query) but cannot get a different random number for each row.
The query optimizer handles all functions as deterministic. So a 
function is only called again when its parameters are different.

> Function Random_Number() As Integer
Make it

   Public Function Random_Number(ADummy As Long) As Integer

> Then, I call the function from a query:
> Field = Number: Random_Number()
And use it

   Number: Random_Number([ID])

where [ID] must be an auto-increment field.


mfG
--> stefan <--
0
Stefan
1/3/2008 11:04:24 AM
Reply:

Similar Artilces:

substracting in query
I have a calculated field in my query where one sum is substracted from another.However when there is nothing in the second field, the result is also nothing, while i want to preserve the first value my expression in the query is : Diff: [imported]-[exported] if i have 100 items imported and nothing exported, the result is nothing, while i want to be 100 How could i achieve that ? -- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/Forums.aspx/access-queries/200712/1 hi, peljo via AccessMonster.com wrote: > I have a calculated field in my query where one sum is...

Random
How to get random numbers random(0xff) ? int RandomNumber = (rand() * 0xff) / RAND_MAX; -- Bjarne Nielsen "]GHO[" <yousefk@taux01.nsc.com> skrev i en meddelelse news:0b6a01c3a84c$5733a890$a501280a@phx.gbl... > How to get random numbers random(0xff) ? rnd()%0x100; or rnd() & 0xff; Ruben On Tue, 11 Nov 2003 04:07:13 -0800, "]GHO[" <yousefk@taux01.nsc.com> wrote: >How to get random numbers random(0xff) ? ...

how would you calculate the number of hits to your website
Hi ,' can some one tell to me the answer of this question On a website, how would you calculate the number of hits to your website ...

Random Numbers not Random
When I create random numbers for an application with the following code, they do not appear to be truely random. Me.RandomNumber = Int(9 * Rnd + 1) ' Random Number 1-9 If I have two users setting side by side, they frequently get the same results when they start up Am I missing somthing? Any help would be appreciated -- Frank Wagner fwagner111@aol.com Frank, Have you tried a Randomize statement just before the RND? That should do it. -- hth Al Campagna Microsoft Access MVP http://home.comcast.net/~cccsolutions/index.html "Find a job tha...

Largest number in range
I am looking for a formula that will select the largest number in a range and make that number "bold." Is there a formula that will do this? Thanks in advance for any help. RBG Not a formula (formulas return values--they don't change formatting). But you could use Format|conditional formatting. If your range is B3:G9, then select that range and with B3 the activecell, then click on Format|conditional formatting Then Condition 1: Formula is and use this as the formula: =B3=MAX($B$3:$G$9) Excel will adjust the formula for all the cells in the selected area. (Don't...

Resequence figure numbers
Version: 2008 Operating System: Mac OS X 10.6 (Snow Leopard) Processor: Intel Using automated figure numbers in captions - have deleted a few, and the remaining ones do not automatically renumber. <br><br>How do I force the figure numbers to resequence? In Word 2007 on a Windows computer, it's just the F9 key. What works for Word 2008 on the Mac? Actually, it's F9 in Mac Word as well � or at least it *was* until Apple decided to expropriate that keystroke for Expose :-) You have several options available to you: 1- In System Preferences> Expose & Spaces...

Numbers matchup
I have a column of Account numbers in one worksheet. In another worksheet i have a column with account numbers and a column with SSN. I need a formula that will take the account number in the first worksheet and find it's match in the second worksheet and plug in the SSN on that same row as the Account number. Is this possible and how would be the best way to do this TIA Paul Have a look in HELP index for VLOOKUP -- Don Guillett SalesAid Software donaldb@281.com "Paul McGuire" <pmcguire@nottelling.com> wrote in message news:%2393selkAFHA.2932@TK2MSFTNGP10.phx.gbl....

Add numbers accross columns after stripping away text
I have the following data in a spreadsheet: A1 B1 C1 D1 E1 F1 4.5f 6f 3.5f 3f 7.25f I need to be able to add the numbers together to give me 24.25, i.e. strip the fs away. The numbers will always be less than 10 and the there will only ever be .25 or.5 or .75 after the number (I don't know whether that is significant?). If anyone can show me how to do this I would be very grateful. I have been messing around with MID and FIND to no avail and then started thinking that SUMPRODUCT might have to get involved but it all got a bit m...

Exchange server randomly asking random users to Authenticate randomly...
Has anyone had a problem like this where a user is in their Exchange mailbox using Outlook 2003 and the server prompts them for their credentials? If they hit cancel and exit out of Outlook and run it again it lets them into their mailbox. Thank you, Benjamin Pls make sure the outlook 2003 Client does not using Cache mode If is ,pls clearn this option -- Jammy "Benjamin Chan" <bchan[pleasenospam]@controlproductsinc.com> ���g��l��s�D :#BxdizrtEHA.3972@TK2MSFTNGP15.phx.gbl... > Has anyone had a problem like this where a user is in their Exchange mailbox > using Outlo...

unable to insert page numbers
my ms word 7 (enterprise package) has ceased to allow my to insert page numbers. Everythng else is working fine. I click "insert", that's ok; I click "page numbers" , that's ok; then I click "top of page" or "bottom, etc." and this is where my word 7 fails because no further option choice appear (though they had before). The only option to appear is "save selection as page number" and this is "grayed out" unless of course I have some current text selected. this is the same problem whether I attempt to insert ...

Criteria in Query
I have a multiuser query that prompts the user for criteria (sorry I do not know the technical terms). Is there a way that I can set this up where the user can type in part of the criteria and it return with all fields that have that part in it? So for example: If the field is state. The criteria in the query has [Enter the State]. I want the user to be able to type Ala and it return Alaska and Alabama. Is there a wild card? I tried entering * after Ala, but that did not work. Can this be done? -- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/Forums.aspx/access-...

Macro to number blank cells
In one row I have: A B C D E F G Cust# Address 1 Address 2 Address3 Address 4 Address5 Address6 I have a macro that inserts 6 rows below each name, how could I copy information in columns B-G to the 6 cells below cust #, Thanks in advance for your help Fernando Can it be this simple? I'm not positive that I understand what you're asking. But try this. You have blank rows below each record. Select the columns B through G, beginning with the first BLANK row and down all rows. Hit Ed...

Generating Correlated Random Values in Excel
Hi Mike, Thanks so much for your advice. I think that I have it figured out, but can you confirm this for me? I can't afford to screw this up. If mean(inflation) = .031 stdev(inflation) = .047 mean(stock return) = .106 stdev(stock return) = .204 Column Headers: A B C D 1 Z1 Z2 Inflation Stock Return Data Generation Formulas A2 =NORMINV(RAND(),0,1) B2 =NORMINV(RAND(),0,1) C2 =0.031+0.047*A2 D2 =0.106+0.204*(A2*rho+B2*(1-rho^2)^0.5) Are these formulas correct to generate the random data? Particularly cell D2. Does this give me a complete value that t...

formula query #2
Hi all, Got a quick question for ya's. I am currently trying to hash out a formula along these lines: =IF(F2="new","=vlookup(A2,p,2,0)",0) I have tried adding the 'indirect' function but it still brings me no joy. Any help would be greatly appreciated. Regards, Rikki Hi Rikki How about: =IF(F2="new",vlookup(A2,p,2,0),0) -- Best Regards Leo Heuser Followup to newsgroup only please. "Chiccada" <Chiccada@discussions.microsoft.com> skrev i en meddelelse news:AF885A19-DB2A-41A2-B7A9-826EB7F341C1@m...

converting "text" numbers to numbers
I have been using the technique of multiplying cells that have number entries that behave like text entries by the value of 1 to convert them to numbers. However, some mixed cell entries, convert strangely. For example the entry "6 A" (without the quotes) becomes 0.25 when multiplied by 1. Any explanation? Any ideas on how to solve other than checking cell by cell to confirm all characters are numbers? Confused! Frustated! <grin>. Bob Just figured out the "why". An entry like 6 A is converted to 6AM. Its numerical value is 0.25. Still hoping for a ...

Sorting imported "numbers"
I've imported a long list of "numbers" from a server. Now in my excel table I can not sort them. I've tried multiplying the col. by "1" from paste special, Add from a free cell and paste special, using a macro form the converting text to number page, using trim and clean function, copy and paste as value, using the text to columns command, all to no avail. The "numbers" still stay left justified and sort by first number, i.e. 113 before 21 etc. There are 1500 entries and I do no think the table woudl be of much use after i tried to re-type in all t...

Addition problem, number always 2 cents off...Help
I have a little problem with my SUMs I have 200 to 300 rows of A * B = C Then I tell it to do a =sum(d1:d300) All the cells are formated to currency, two decimal places. when I add up the numbers with an adding machine I'm always 2 - 22 cents off. (2 cents on this sheet, 22 cents on another sheet....) Can anyone help Thank you WTG The issue is very likely to be rounding - that the product of each multiplication has fractional cents that Excel considers in the SUM() function, even though you don't see them fractional cents on screen You can either modify your multiplication f...

Auto Numbering
I want to be able to increase my ID field for each new record I enter, but I don't want to use an autonumber field in my table. I have used the following: ID = Nz(DMax("[id]", "tblNames")) + 1 and put it in the On Current property of the form. The problem is that when the last field is completed and the user presses Enter, the new record automatically puts in the new ID number. What I want to do is for the form to put in the next ID number but only when the 2nd field has data entered in it. Thanks Nigel, Place your code into the AfterUpdate event of the second ...

random pages
I have developed pages that randomly define a set of normal lung function data based on gender, age and height. I have applied formulas to this data simulate 5 classic lung function abnormalities (normal, restrictive, obstructive, mixed and early obstructive.) Currently the sheets that define the abnormal are named by one of the above lung abnormalities. I would like to present data from random pages in a work book to students and rather than have the pages named by the abnormality be named a simulated patient name. My questions. Can I have the name of a sheet set to equal data from to ...

How to show what record number you are on in form?
I have created an unbound form in Access 2007 and am listing the records which are in my table. I found out how to show how many records there are in the table but would also like to show which record you are on. For example, when I click the next button to see the next record it will show: "Record 2 Of 30", and so on. This is the one I used to count the amount of records: Dim countRecords As Long countRecords = DCount("customerNumber", "customer") Me.txtRecordAmount = "Record # Of " & countRecords How can I show what reco...

Random Distribution
I need to randomly order numbers from a list or range of consecutive whole numbers, such that each number is listed only once. Can this be done in excel using functions, formulas or whatever? I want to incorporate it into a spreadsheet with a macro to automatically generate the list and use it to randomly designate selected entries. "Rick via OfficeKB.com" wrote: > I need to randomly order numbers from a list or range of consecutive whole > numbers, such that each number is listed only once. Can this be done in > excel using functions, formulas or whatever? I want to...

Numbering Heading
Is there a way I can number heading and then continue with the same numbering level on the ensuing paragraphs, eg 1. First Heading 1.1 kdkdkdk 1.2 dldldldldl 2. Second Heading 2.1 ldldld 2.2 ldldldl -- Trainer See http://www.shaunakelly.com/word/numbering/OutlineNumbering.html for general principles. If you have Word 2007, the implementation is slightly different (through Define New Multilevel List), but the principles are the same. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA http://word.mvps.org "Trainer&quo...

How to Retrieve Random Records through webservice method
Hi All, I'm writing an application that retrieve records from CRM 3.0 automatically using the web service. My question is, is there any way we can retrieve records randomly by using any webservice method? Like we can use RAND() or NEWID() to achieve this in SQL. Please help me if you have any idea about it. My sample method code is given below: CrmService service = new CrmService(); RetrieveMultipleRequest request2 = new RetrieveMultipleRequest(); // Create the ConditionExpression object. ConditionExpression condition = new ConditionExpression...

outline numbered list not auto-numbering
I have 2003 version of Word at work. I am trying to create an outline numbered list with 3 levels. When I hit the enter button after typing the text for an item, word does not seem to recognize that it should continue the list. The next line just has normal formatting, and I'm forced to use the format painter brush to copy a previous item from the list, and then Word seems to recognize it as part of the list. I have verified the "Apply Automatic Numbered Lists" is checked in the Tools/Autocorrect Options/Autoformat as you type menu. An observation about Word ...

Random numbers
How exactly do i generate random numbers in VC++.Is the a function similar to random() in C++.Thanks in advance Fenn On Mon, 10 Jan 2005 22:42:52 -0800, "Fenn" <fenn_j@yahoo.com> wrote: >How exactly do i generate random numbers in VC++.Is the a function similar >to random() in C++.Thanks in advance > VC++i is C++. Besides, there is no random() in C++. I think you mean rand(). And besides, that is a C function imported into C++. In any event, generate random numbers in Visual C++ using MFC exactly the same way you would in any C++ (or C) program. .. yeah, b...