Solved

ColdFusion Help with update statement

Posted on 2014-03-01
2
230 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

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

911 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

16 Experts available now in Live!

Get 1:1 Help Now