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!

Help

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Forgive me, new to delphi.

Trying to put the current record number into a field when a new record is create......any help much appreciated.

Steve
 
this depends on the Database.

MsAccess and SQLServer (Paradox I think too) have AutoInc Field types.

Using Oracle you have to use a sequence to generate a unique number.

Usin Interbase there is a feature like oracle sequences but I don' remember me.


 
Which database are you using, if it is for generating an unique number, there are several work-outs.
What is the purpose?
S. van Els
SAvanEls@cq-link.sr
 
It will be for a DBF Fox Pro format, I want to create a unique number that follows in sequence from the last record that was created. Record 1 being number "1" then adding one to the next record created. This number will need to be stored in a field in the table, this way I can use the unique field to reference another table.

Many Thanks
 
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;
S. van Els
SAvanEls@cq-link.sr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top