Hi

I needed the ID number of a form (its autonumber when inserted), so do this
I used the SQL max function to optain, the last entry, therefore the last
autonumber and then added 1 to it.

Heres the code

<cfquery name="getform" datasource="#travelDS#">
select MAX(id) as test
from forms
</cfquery>

<cfset trnumber=#getform.test# + 1>

HTH
mark
-----Original Message-----
From: Shannon Rhodes [mailto:[EMAIL PROTECTED]]
Sent: 01 August 2001 14:41
To: CF-Talk
Subject: Question: Creating a primary key field


Is it possible to query which was the last ID number created (autonumber
field in Access) for the purpose of adding 1 to explicitly state the new ID
number for a newly created record?

The reason why I ask is that I'm having trouble inserting my new info into
two separate tables because I need the newly created ID number for table A
to be inserted into table B.  If I can't "guess" what the number will be,
I'm stuck trying to take the user through a second page where I insert into
table A then turn around and query the new record to insert the new field
into table B.  That leaves me with the problem of what to do if the user
abandons the application on the second page, leaving no new record created
in table B.

This may sound like screwy application design (and maybe it is, I'm still
pretty new at this), but the problem is that table A contains contact
information, while table B contains all other information (class
registration, payment methods, etc), and they have a one-to-one relationship
because I may need to change which person the info is associated with (it's
possible that a person will register and pay for a class, but a co-worker
will attend in their place).  I can't make the classID a primary key in
table B either (the person could decide to switch classes) so I just have an
autonumber as a primary key.  Argh!  All suggestions welcomed.

TIA,
Shannon
[EMAIL PROTECTED]



FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to