Random between value in field table

  • Thread starter Thread starter barbun
  • Start date Start date
B

barbun

Hi from italy ,
so sorry for my bad english...................

I have a table "Pronostico" with only one field "NR" and in this field
example there are this values :

2
4
6
8
10
12 ecc

I search to write a vba code to generate a random number THAT THERE ARE in
value above, example i want return

6
8
10
4
6
ecc. ecc

I have write this code, but is wrong because return value to 1 to first
value in "NR"

Public Sub test()
Dim Num1 As Byte
DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE * FROM Colonne;"
DoCmd.SetWarnings True
Set rst = CurrentDb.OpenRecordset("Colonne")
Set vin = CurrentDb.OpenRecordset("Pronostico")
For x = 1 To 10
Num1 = Int(Rnd(1) * vin!Nr) + 1
rst.AddNew
rst!Num1 = Num1
rst.Update
Next x
End Sub


How change ????

Many thanks !!
 
Are you wanting to:

1) just sort your records randomly, which gives you the exact same records
just in a different order, or

2) Randomly choose records from Pronostico to insert into Colonne, which may
result in duplicate values in Colonne, with some records in Pronostico not
being copied into Colonne at all.

I've done it both ways, so let me know which one you're trying to do, and I
can help with the code.

Ciao,
Michelle
 
Ciao !!!!!

2) Randomly choose records from Pronostico to insert into Colonne, which may
result in duplicate values in Colonne,

I search this !


And Now I hope i don't confuse you, but if you want know what i search in
definitive mode , is this :

In a table "Pronostico" I put in the field "NR" sometime 20 value ,
sometimes 22 value, sometimes 23 value
In all case the value is from 1 to 32 !!
I simple search a vba module that generate all combination from the value in
"Pronostico"!NR" take for classes 8 .


Big Example :)
In table "Pronostico" Field "Nr" I have :

2
3
5
7
8
9
10
12
14
16
18
19
20
23
24
25
28
30

I want generate all possibile combination takes for classe 8 :

2 3 5 7 8 9 10 12
2 3 5 7 8 9 10 14
2 3 5 7 8 9 10 16
2 3 5 7 8 9 10 18
2 3 5 7 8 9 10 19
ecc ecc

this is the code that i have write :

Public Sub Random32VP()


Dim Num1 As Byte
Dim Num2 As Byte
Dim Num3 As Byte
Dim Num4 As Byte
Dim Num5 As Byte
Dim Num6 As Byte
Dim num7 As Byte
Dim num8 As Byte


Dim limetesup As Byte
Dim limiteinf As Byte

Dim rst As DAO.Recordset
Dim vin As DAO.Recordset



Dim x As Long


Randomize Time

DoCmd.SetWarnings False

DoCmd.RunSQL "DELETE * FROM Colonne;"
DoCmd.SetWarnings True

DoCmd.OpenQuery "PronosticoSettimana"


Set vin = CurrentDb().OpenRecordset("Pronostico")
Set rst = CurrentDb().OpenRecordset("Colonne")



Num1 = vin!Nr To vin!Nr
For Num2 = vin!Nr To vin!Nr
If Num2 <> Num1 Then
For Num3 = vin!Nr To vin!Nr
If Num3 <> Num1 And Num3 <> Num2 Then

For Num4 = vin!Nr To vin!Nr
If Num4 <> Num1 And Num4 <> Num2 And _
Num4 <> Num3 Then

For Num5 = vin!Nr To vin!Nr
If Num5 <> Num1 And Num5 <> Num2 And _
Num5 <> Num3 And Num5 <> Num4 Then

For Num6 = vin!Nr To vin!Nr
If Num6 <> Num1 And Num6 <> Num2 And Num6 <> _
Num3 And Num6 <> Num4 And Num6 <> Num5 Then

For num7 = vin!Nr To vin!Nr
If num7 <> Num1 And num7 <> Num2 And num7 <> _
Num3 And num7 <> Num4 And num7 <> Num5 And num7 <> Num6 Then

For num8 = vin!Nr To vin!Nr
If num8 <> Num1 And num8 <> Num2 And num8 <> _
Num3 And num8 <> Num4 And num8 <> Num5 And num8 <> Num6 And num8 <> num7
Then


rst.AddNew
rst!Num1 = Num1
rst!Num2 = Num2
rst!Num3 = Num3
rst!Num4 = Num4
rst!Num5 = Num5
rst!Num6 = Num6
rst!num7 = num7
rst!num8 = num8
rst.Update

End If
Next num8
End If
Next num7
End If
Next Num6
End If
Next Num5
End If
Next Num4
End If
Next Num3
End If
Next Num2
Next Num1


End Sub




the problem is change the wrong = vin!Nr To vin!Nr

in the correct ???????

if you don't understand any word....you have ragion !!!!!!!


can help me ?

As you understand ..this is to play a similar lottery !
 
OK, is this what you mean?

Pronostico contains numbers that you can use in the lottery (NR1). Colonne
contains all the different variations for those numbers, up to 8 fields
(NR1, NR2, ... NR8). You want Colonne to contain all possible variations of
32 numbers? That will end up with a LOT of combinations - is this want you
want, or just a few combinations, say 10?

Let me know and I can keep thinking on this...
michelle
 
Michelle said:
OK, is this what you mean?

Pronostico contains numbers that you can use in the lottery (NR1). Colonne
contains all the different variations for those numbers, up to 8 fields
(NR1, NR2, ... NR8).

Yes it is !!!!!


You want Colonne to contain all possible variations of
32 numbers? That will end up with a LOT of combinations - is this want you
want, or just a few combinations, say 10?

If we take all number from 1 to 32 are 10.518.300 combination ...many :)
so i take put 20, 22, 23 number in "Pronostico" so if are
20 = 125.970 combination
22 = 319.770 combination
19 = 75.582 combination

if is possible i want generate all .......

you have to know that sometimes i put in "Pronostico" 19 value, sometimes 20
value, sometimes 21,
we can say between >12 and <22 :)


Let me know and I can keep thinking on this...

i hope was clear.....many tk

ciao vincenzo
 
OK, I understand what you're wanting, but I can't make it work yet in
Access. I'll keep trying different methods.
 
Back
Top