check to see if value is repeated

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to see if a value is repeated in my one field called GeneticIDnum.
The table it is in is Table: Genetic ID num.

What I need to do is to check all of the GeneticIDnum in the the table to
see if the new random number that was generated is the same as one in the
table. If it is then I need to make another random number. If it is not in
the table then I need to put it into the table.

I need some help with the VB code to do this. It would be greatly
appreciated for some help.


Here is my code for the random number:
Randomize

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

randomNumber = Rnd
 
Hi,
You could use the DCount function for this:

If DCount("[GeneticIDnum]","[Genetic ID num]","GeneticIDnum = " & randomNumber) > 0 Then
'you need to choose another number
End If

HTH
 
Would this check all of the values in the GeneticIDnum field or would it only
check the first one?

How would you get it to check the field and then move to the next one till
all of them are checked?

Dan Artuso said:
Hi,
You could use the DCount function for this:

If DCount("[GeneticIDnum]","[Genetic ID num]","GeneticIDnum = " & randomNumber) > 0 Then
'you need to choose another number
End If

HTH
-------
Dan Artuso, MVP

pokdbz said:
I need to see if a value is repeated in my one field called GeneticIDnum.
The table it is in is Table: Genetic ID num.

What I need to do is to check all of the GeneticIDnum in the the table to
see if the new random number that was generated is the same as one in the
table. If it is then I need to make another random number. If it is not in
the table then I need to put it into the table.

I need some help with the VB code to do this. It would be greatly
appreciated for some help.


Here is my code for the random number:
Randomize

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

randomNumber = Rnd
 
Hi,
DCount will provide a count of ALL values that are equal to your random number.
Help will explain it in more depth.

--
HTH
-------
Dan Artuso, MVP

pokdbz said:
Would this check all of the values in the GeneticIDnum field or would it only
check the first one?

How would you get it to check the field and then move to the next one till
all of them are checked?

Dan Artuso said:
Hi,
You could use the DCount function for this:

If DCount("[GeneticIDnum]","[Genetic ID num]","GeneticIDnum = " & randomNumber) > 0 Then
'you need to choose another number
End If

HTH
-------
Dan Artuso, MVP

pokdbz said:
I need to see if a value is repeated in my one field called GeneticIDnum.
The table it is in is Table: Genetic ID num.

What I need to do is to check all of the GeneticIDnum in the the table to
see if the new random number that was generated is the same as one in the
table. If it is then I need to make another random number. If it is not in
the table then I need to put it into the table.

I need some help with the VB code to do this. It would be greatly
appreciated for some help.


Here is my code for the random number:
Randomize

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

randomNumber = Rnd
 
Back
Top