Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Primary Key is created after certain fields are populated

Status
Not open for further replies.

Mike555

Technical User
Feb 21, 2003
1,200
US
How can you setup a primary key so that it is created only after 3 record fields are created?

Example...I want my primary key (name = ID) to be created after data is put in the text fields market, value, invoice.

Thanks.

--
Mike

Man usually avoids attributing cleverness to somebody else -- unless it is an enemy. - A. Einstein
 
Assume that your primary key is an autonumber? Access allocates the autonumber as soon as it creates a new record. A possible workaround is to put the data into global constants initially and then create a record using DAO or ADO (depending on your version of Access). You'd have to write a few lines of Visual Basic to achieve this. Re-post if this is not clear.

Access makes all things possible. It even makes them intelligible
 
May I ask what the purpose of creating a primary key AFTER inserting records is ... ?

Transcend
[gorgeous]
 
You can create the primary key value whenever you want [/b]before[/b] saving the record if you use a form.
Use the BeforUpdate event of the form to calculate it.

But don't calculate your primary key as a combination of other fields! The primary key in a table must be independant!!!

Either set your primary key on n fields (n being the number of fields that make a unique concatenated value) or make it on a numeric (AutoNumber or Long Integer) field.

If AutoNumber, never give the primary key any meaning to the user. Its only purpose is to uniquely identify each record in a table. To eliminate the temptation, set it as Random, not Incremented...

If Long Integer, you'll have to calculate it by code everytime a record is inserted.

HTH


[pipe]
Daniel Vlas
Systems Consultant

 
Oh right I think i was confused

you mean calculate it after you have put certain fields in as opposed to creating a primary key column ... like in the table design

Transcend
[gorgeous]
 
Thanks for all the info. I've figured the easiest way to go would be the auto number.

--
Mike

Man usually avoids attributing cleverness to somebody else -- unless it is an enemy. - A. Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top