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(A RGUMENTS.A cademicsCo mments)#',
Faculty='#Trim(ARGUMENTS.F aculty)#',
FacultyComments='#Trim(ARG UMENTS.Fac ultyCommen ts)#',
Athletics='#Trim(ARGUMENTS .Athletics )#',
AthleticsComments='#Trim(A RGUMENTS.A thleticsCo mments)#',
Spiritualvitality='#Trim(A RGUMENTS.S piritualvi tality)#',
SpiritualvitalityComments= '#Trim(ARG UMENTS.Spi ritualvita lityCommen ts)#',
Facilities='#Trim(ARGUMENT S.Faciliti es)#',
FacilitiesComments='#Trim( ARGUMENTS. Facilities Comments)# ',
otherComments='#Trim(ARGUM ENTS.other Comments)# ',
resource='#Trim(ARGUMENTS. resource)# ',
cur_datetime= #CreateODBCDate(ARGUMENTS. cur_dateti me)#,
name='#Trim(ARGUMENTS.name )#'
</cfquery>
<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
AcademicsComments='#Trim(A
Faculty='#Trim(ARGUMENTS.F
FacultyComments='#Trim(ARG
Athletics='#Trim(ARGUMENTS
AthleticsComments='#Trim(A
Spiritualvitality='#Trim(A
SpiritualvitalityComments=
Facilities='#Trim(ARGUMENT
FacilitiesComments='#Trim(
otherComments='#Trim(ARGUM
resource='#Trim(ARGUMENTS.
cur_datetime= #CreateODBCDate(ARGUMENTS.
name='#Trim(ARGUMENTS.name
</cfquery>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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\newl ifefc\surv ey\survey. cfc: line 96
Called from C:\CFusionMX7\wwwroot\newl ifefc\surv ey\survey_ process.cf m: line 63
Called from C:\CFusionMX7\wwwroot\newl ifefc\surv ey\survey. cfc: line 96
Called from C:\CFusionMX7\wwwroot\newl ifefc\surv ey\survey_ process.cf m: line 63
94 : INSERT INTO nlfcssurvey(AutoID,Academi cs,Academi csComments ,Faculty,F acultyComm ents,Athle tics,Athle ticsCommen ts,Spiritu alvitality ,Spiritual vitalityCo mments,Fac ilities,Fa cilitiesCo mments,oth erComments ,resource, cur_dateti me,name)
95 :
96 : SELECT #holdtemp#+1,'#Trim(ARGUME NTS.Academ ics)#','#T rim(ARGUME NTS.Academ icsComment s)#','#Tri m(ARGUMENT S.Faculty) #','#Trim( ARGUMENTS. FacultyCom ments)#',' #Trim(ARGU MENTS.Athl etics)#',' #Trim(ARGU MENTS.Athl eticsComme nts)#','#T rim(ARGUME NTS.Spirit ualvitalit y)#','#Tri m(ARGUMENT S.Spiritua lvitalityC omments)#' ,'#Trim(AR GUMENTS.Fa cilities)# ','#Trim(A RGUMENTS.F acilitiesC omments)#' ,'#Trim(AR GUMENTS.ot herComment s)#','#Tri m(ARGUMENT S.resource )#',#Creat eODBCDate( ARGUMENTS. cur_dateti me)#,'#Tri m(ARGUMENT S.name)#'
97 :
98 : FROM nlfcssurvey
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\newl
Called from C:\CFusionMX7\wwwroot\newl
Called from C:\CFusionMX7\wwwroot\newl
Called from C:\CFusionMX7\wwwroot\newl
94 : INSERT INTO nlfcssurvey(AutoID,Academi
95 :
96 : SELECT #holdtemp#+1,'#Trim(ARGUME
97 :
98 : FROM nlfcssurvey
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.
just to test your query, change AutoID in your code to a number you're sure it doesn't exists.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@Nigel-SA,
Why not just make the column an autonumber?
Why not just make the column an autonumber?
ASKER
thanks, saved my bacon....
ASKER
must it look like
SELECT' #holdtemp#+1', '#Trim(ARGUMENTS.Academics