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!

Paradox Table: how to avoid key violation 1

Status
Not open for further replies.

guava65

Programmer
Jul 20, 2001
238
US
I'm trying to input data to a paradox table with three (3) fields: ID, Date, Comment. the only key is the ID field.

When I enter a duplicate ID. I get a "key violation" error. :-V How do I avaoid this? I do not want the key field to be unique. :-V Is there a special way to handle this with a paradox table? I have no problems with dBase tables.

Thank you in advance.

cg

Mahalo,
cg
 
You could add an autoinc key field. Make that field your primary key. Paradox will automatically put a new number in that field every time you add a record, and then you shouldn't have to worry about it.

Good luck!
TealWren
 
The AutoInc Field will work in a single user environment, if there is a possibility that more then one user or application will access the database, it should be avoided.
A work around is described below

Ok first you have to create a counter table which stores the next ID number(1 record, 1 field).

inserting a new record;

a) Open the counter table
b) Retrieve the number
c) Increase the counter
d) Close the counter table;

Create your CounterTable
NextRecord --> integer;
fill in your starting value (100);

Create your main table, (Main_table) where your ID_field is an integer key field

On Newrecord event handler:

procedure Main_TableNewRecord(DataSet: TDataSet);
begin
with COUNTERTABLE do
begin
Open;
try
edit;
Main_TableIDfield.Value := NEXTRECORD.Value; // retrieve number
NEXTREC.Value := NEXTREC.Value + 1; // update counter
Post; //close the Counter table
finally
Close;
end;
end;
end;


Regards S. van Els
SAvanEls@cq-link.sr
 
Thanks.

This is similar to what I have done in the past to generate purchase order and invoice numbers. I'll use this technique in this case as well.

cg Mahalo,
cg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top