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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unique field problem

Status
Not open for further replies.

woodyinoz

IS-IT--Management
Jan 8, 2002
215
GB
I am having real problems with creating a unique field in my main table.
The problem arises because I am importing a text file into the table and the text file does not actually contain a unique field itself.
I have tried out an autoincrement field but this causes existing code that inserts extra records according to a value in the ‘quantity’ field to fail.

Can anybody suggest a way of automatically inserting a value that could be unique for each record?

Thanks,
Woody
 
Woody,

Typically, you create an arbitrary key by adding a longInt field and flagging it as the key field. Then, at runtime, you incremement that yourself when fields are added.

For example:

Code:
   if eventInfo.id() = dataInsertRecord then
      doDefault
      ID.Value = getNextNum( ID.TableName, ID.FieldName )
   endIf

In this snippet, getNextNum() is a custom procedure that looks up the table and field bound to the object called ID, increments a counter, and then returns the new value. In turn, this is assigned to the ID field.

RDA has an inexpensive add-in for doing this as painlessly as possible. Take a look at the description of AutoKey on which ranges from $20 to $30 per license, depending on the package you get.

Once you've got the mechanism for creating the unique ID, you can apply it by importing your data in a two step process:

1. Import the file into a temporary, unindexed table.

2. After the records are imported, use ObjectPAL to dump the results into your real table. Be sure to call your incrementing utility as needed.

The main reason for the code intensive approach is networking flexibility. If I have, say, twelve people adding data into the table at run time, I need to make sure the application handles the case where one person adds a new record and then waits before posting it.

Hope this helps...

-- Lance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top