Solved

ColdFusion Help with update statement

Posted on 2014-03-01
2
231 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
ID: 39897658
(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
ID: 39897910
Plan b worked perfectly - thanks!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

770 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