Solved

ColdFusion Help with update statement

Posted on 2014-03-01
2
228 Views
Last Modified: 2014-03-01
I have a working update statement that updates more than one record at a time (with one table) and need to alter to accommodate another table of alterations, meaning some records of the main table have a alteration record attached and some don't.

I'm using counter for multiple inputs:
<cfloop from="1" to="#form.numOfFields#" index="counter">
       <!--- extract values of form fields --->
       <cfset variables.keyID   = FORM["keyid_"& counter]>
       <cfset variables.date = FORM["date_"& counter]>
Problem:
When I added this statement, to receive inputs for the alteration table, I receive errors due to not all records from the main table, have records from the alteration table:
      <cfset variables.AlterationTabledate = FORM["REC_DATE_B"& counter]>
This statement works when all records being displayed have an alteration record.

Error received if all records displayed do not have an alteration record:
Element DATE_B2 is undefined in a Java object of type class coldfusion.filter.FormScope.

How can I make this update statement work when not all records of the main table have an alternate record attached?
0
Comment
Question by:DJPr0
2 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
Comment Utility
(BTW, Since your question is about CF, it really should have been posted under one of the CF topics, not Access (it won't get the right attention there).  I just saw it by accident... )

If I'm understanding correctly, either

a) Use cfparam to assign a default value for the field, so it always exists. That'll avoid the error
 
<cfparam name="FORM.REC_DATE_B#counter#" default="(some default value")>
<cfset variables.AlterationTabledate = FORM["REC_DATE_B"& counter]>

b) OR you could use structKeyExists and only do something if that field DOES exist

<cfif structKeyExists(FORM, "REC_DATE_B"& counter)>
       the form field exists, do something here
</cfif>

Which one is better all depends what your code is doing.
0
 

Author Closing Comment

by:DJPr0
Comment Utility
Plan b worked perfectly - thanks!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now