Auto Populate Field

E

Eric Starn

I have a data entry form that I created. In that form I have a [Asset ID]
field that I would like to have auto populate with a random four digit number
when it open to a new record.
I am not sure if this is possible and if so how can it be accomplished?

Any help will be greatly appreciated.

Eric
 
E

ErezM via AccessMonster.com

use the BeforeInsert event of the form to run this code:
Randomize
[Asset ID]=int(rnd(1)*10000)

that code will set a random number (between 0 and 9999) to asset id just
before a new record is added


Eric said:
I have a data entry form that I created. In that form I have a [Asset ID]
field that I would like to have auto populate with a random four digit number
when it open to a new record.
I am not sure if this is possible and if so how can it be accomplished?

Any help will be greatly appreciated.

Eric
 
J

Jeff Boyce

Eric

"random" doesn't mean "unique" ... you have some pretty decent statistical
odds of ending up with more than one record "sharing" the same ID.

If that's acceptable, see other responses.

If that's unacceptable, consider using the Access Autonumber data type for a
primary key field. The Autonumber is intended for use as a unique row
identifier. NOTE: Access Autonumbers are generally unfit for human
consumption. If you are looking for a unique row identifier, use an
Autonumber. If you are (also) looking for a human-readable ID #, you will
need to (also) add a field to hold that number, and come up with a function
to generate it.

Good luck!

Regards

Jeff Boyce
Microsoft Office/Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top