Avatar of Nigel-SA
Nigel-SA
 asked on

Insert New Record into MS Access

HELP URGENT, I'm trying to insert a new record into ms access database for a survey, but current code below only updates the same record.  I know this is simple but can't get it adding new record and it needs to be done by today.  The AutoID is set to primary field in database, with "Number" not "Autonumber" as data type.   thanks

<cfset ds="nlfcsdb">

<cfquery name="key" datasource="#ds#">
select max(AutoID) as AutoIDhold from nlfcssurvey
</cfquery>

<cfset holdtemp = #key.AutoIDhold#>

  <!--- Update survey Details --->
  <cfquery name="keytest" datasource="#ds#">
 
  UPDATE nlfcssurvey
 
  SET
 
  AutoID=#holdtemp#+1,
  Academics='#Trim(ARGUMENTS.Academics)#',
  AcademicsComments='#Trim(ARGUMENTS.AcademicsComments)#',
  Faculty='#Trim(ARGUMENTS.Faculty)#',
  FacultyComments='#Trim(ARGUMENTS.FacultyComments)#',
  Athletics='#Trim(ARGUMENTS.Athletics)#',
  AthleticsComments='#Trim(ARGUMENTS.AthleticsComments)#',
  Spiritualvitality='#Trim(ARGUMENTS.Spiritualvitality)#',
  SpiritualvitalityComments='#Trim(ARGUMENTS.SpiritualvitalityComments)#',
  Facilities='#Trim(ARGUMENTS.Facilities)#',
  FacilitiesComments='#Trim(ARGUMENTS.FacilitiesComments)#',
  otherComments='#Trim(ARGUMENTS.otherComments)#',
  resource='#Trim(ARGUMENTS.resource)#',
  cur_datetime= #CreateODBCDate(ARGUMENTS.cur_datetime)#,
  name='#Trim(ARGUMENTS.name)#'
 
  </cfquery>
Web ServersMicrosoft Access

Avatar of undefined
Last Comment
Nigel-SA

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Wim

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Nigel-SA

ASKER
almost there, what about the '

must it look like

SELECT' #holdtemp#+1', '#Trim(ARGUMENTS.Academics)#', ....
Nigel-SA

ASKER
Error Executing Database Query.  
The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again.  
 
The error occurred in C:\CFusionMX7\wwwroot\newlifefc\survey\survey.cfc: line 96
Called from C:\CFusionMX7\wwwroot\newlifefc\survey\survey_process.cfm: line 63
Called from C:\CFusionMX7\wwwroot\newlifefc\survey\survey.cfc: line 96
Called from C:\CFusionMX7\wwwroot\newlifefc\survey\survey_process.cfm: line 63
 
94 :   INSERT INTO nlfcssurvey(AutoID,Academics,AcademicsComments,Faculty,FacultyComments,Athletics,AthleticsComments,Spiritualvitality,SpiritualvitalityComments,Facilities,FacilitiesComments,otherComments,resource,cur_datetime,name)
95 :  
96 :   SELECT #holdtemp#+1,'#Trim(ARGUMENTS.Academics)#','#Trim(ARGUMENTS.AcademicsComments)#','#Trim(ARGUMENTS.Faculty)#','#Trim(ARGUMENTS.FacultyComments)#','#Trim(ARGUMENTS.Athletics)#','#Trim(ARGUMENTS.AthleticsComments)#','#Trim(ARGUMENTS.Spiritualvitality)#','#Trim(ARGUMENTS.SpiritualvitalityComments)#','#Trim(ARGUMENTS.Facilities)#','#Trim(ARGUMENTS.FacilitiesComments)#','#Trim(ARGUMENTS.otherComments)#','#Trim(ARGUMENTS.resource)#',#CreateODBCDate(ARGUMENTS.cur_datetime)#,'#Trim(ARGUMENTS.name)#'
97 :  
98 :   FROM nlfcssurvey

 
Wim

The AutoID you want to insert already exists or if you have more fields that have the property 'Indexed" on 'Yes (No Duplicates)'.

just to test your query, change AutoID in your code to a number you're sure it doesn't exists.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
SOLUTION
trailblazzyr55

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
_agx_

@Nigel-SA,

Why not just make the column an autonumber?

Nigel-SA

ASKER
thanks, saved my bacon....