Generate Error Message

  • Thread starter Thread starter MackBlale
  • Start date Start date
M

MackBlale

I have the following code which at the press of a button generates and
assigns a random 4 digit number as an employee id. When a duplicate is found
I need to generate an error message that says, "Duplicate Found! Please
generate again.

Private Sub GenerateNum_Click()
Dim intMyRanID As Integer
Do
intMyRanID = Int((10000 - 1 + 1) * Rnd() + 1)
Me.ClientID = intMyRanID
Loop While DCount("ClientID", "tblEmployees", "ClientID=" & intMyRanID) > 0
End Sub

Thanks,
Gregory
 
I have the following code which at the press of a button generates and
assigns a random 4 digit number as an employee id.  When a duplicate isfound
I need to generate an error message that says, "Duplicate Found! Please
generate again.

Private Sub GenerateNum_Click()
Dim intMyRanID As Integer
Do
    intMyRanID = Int((10000 - 1 + 1) * Rnd() + 1)
Me.ClientID = intMyRanID
Loop While DCount("ClientID", "tblEmployees", "ClientID=" & intMyRanID)> 0
End Sub

Thanks,
Gregory

I guess there are a few ways you could do what you want but before
discussing them I have to ask why the number has to be random. Why
can;t it be the highest existing number plus 1? WOuld be much easier
to implement.

Bear
 
Bear,
I'm prett set on the random number. Took two months of explaining why just
to get to this point. Trust me it is a necessary evil. When I tested the
button with numbers 1-10 when I generated a duplicate the form would freeze.
I should have less of a chance with 10,000 numbers and only 1000 employees
but if the same number is generated I would like some type of error message.
Hope this helps you help me.

Mack
 
Back
Top