Rnd generates same number after closing and reopening the database.

vgersghost

Vgersghost
Local time
Today, 17:25
Joined
Apr 29, 2005
Messages
106
Randomize (957426813)
Me.txtInvoice = CDate2Julian(Date) & MyYear & (Int((14035 + 1) * Rnd + 3))
Me.txtInvoice = Me.txtInvoice + Me.cboAcctNo + 3


These lines of code are in my program to generate a random invoice number after a data is enter in another combo box. It does okay at generating a random number, but the problem I have is when I closed out of the database, and reopen it and generate an invoice I get the exact same sequence of random numbers. Running Access 2003. I have tried different approaches, Randomize (now()), (Rnd(456) * rnd(984)), adding two lines of the exact same code. The program still ends up generating the same sequence of invoice numbers after closing and opening the database.

Any ideas on how to solve this problem?
 
rather than use a constant variable with rnd (which will always produce the same results) use rnd with a field that contains a number (autonumber field for instance)
 
Or use timer...
 
if the form is bound just use an random autonumber in the table

peter
 
Thanks

The autonumber is not feasible, because the invoice is tied into a Julian date code. I've tried rnd(timer()) and it seems to have solve the problem. I only generated one duplicate invoice number (first entry) after closing and reopening the database. Not the continuous duplicates I was getting.
 

Users who are viewing this thread

Back
Top Bottom