This is how I get the key value of a record that I just inserted.  This is
done with a Sybase database with an autonumber field.  I don't use Access
hardly at all, so I don't know if there is anything equivilent, but maybe
this will give you some ideas, or direction.

<cftransaction action="BEGIN">
    <cfquery name="qryInsert" datasource="#DSN#">
        INSERT INTO table (blah1, blah2, blah3)
        VALUES ('#Form.txtBlah1#', '#Form.txtBlah2#', '#Form.txtBlah3#')
    </cfquery>

    <cfquery name="qryGetID" datasource="#DSN#">
        SELECT @@identity as new_id
    </cfquery>
</cftransaction>

All I have to do to refer to the primary key of the record I just created is
use #qryGetID.new_id#, or I can set it to a Session.Variable, or whatever.
<cftransaction> is important to avoid mixing up the info that is retieved in
case the same table is accessed by 2 different transactions at the same
time, among other things.

Hope that helps at least a little.

.Todd

----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, May 02, 2000 12:54 PM
Subject: Getting Key Field after Insert


> I am using Microsoft Access Autonumber to create Key fields for me.
>
> 1.  Is this a wise thing to do?
> 2.  If  ok , anyone have  a nice way of getting the key back.  I am
currently
> saving a temporary key in one the fields, then finding and changing.  This
> seams like a lot of work to create an Insert.
> 3.  If not, and this might explain all of the discussion about key
creation,
> what was the consensous on the best way to generate a unique key?
>
> Thanks,
> Andy


------------------------------------------------------------------------------
Archives: http://www.eGroups.com/list/cf-talk
To Unsubscribe visit 
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a 
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.

Reply via email to