473,671 Members | 2,171 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to I create blank columns using QueryAddColumn?

Haitashi
96 New Member
Hi:

I need to dymanically create a number of columns using the queryAddColumn function.

I was going to use the loop below. That way each column would have a generic dynamically created name.

Expand|Select|Wrap|Line Numbers
  1. <cfloop index="I" from="1" to="#Variables.qProgramDetails.recordcount#">
  2.     <cfset temp = QueryAddColumn(#this.RecordSet#, "Detail#I#", "VarChar", newArray) />
  3. </cfloop>
The problem I'm encountering is that when running that code I get an error that says: "The column name (Detail1) that you specified already exists in this query".

I'm guessing something isn't quite right since apparently on the second iteration of this loop the column name isn't updating to "Detail2".

Any ideas? As always, thanks in advance!! =)
Mar 2 '09 #1
4 5314
acoder
16,027 Recognized Expert Moderator MVP
...or perhaps the query already has a column named Detail1. Is this.RecordSet an empty query before the loop?
Mar 4 '09 #2
cymark
2 New Member
Try this:

Expand|Select|Wrap|Line Numbers
  1. <cfloop ....>
  2.  
  3.    <cfset col = "Detail"&#I#>
  4.    <cfset temp = QueryAddColumn(#this.RecordSet#, "#col#", "VarChar", newArray) />
  5.  
  6. </cfloop>
Or try dynamic variables - lookup Evaluate function.

Good luck - CM
Mar 9 '09 #3
acoder
16,027 Recognized Expert Moderator MVP
cymark, welcome to Bytes and thanks for your contribution.

You could do away with the pound signs in the cfset statement, i.e.
Expand|Select|Wrap|Line Numbers
  1. <cfset col = "Detail"& I>
In this case, however, the code that you've posted won't make a difference because it does recognise "#I#" to be 1 (see error message).
Mar 10 '09 #4
cymark
2 New Member
Hi,

Sorry was a bit quick there.

The following seems to work OK:

Expand|Select|Wrap|Line Numbers
  1. <cfset myQuery = QueryNew("")>
  2.  
  3. <cfset FastFoodArray = ArrayNew(1)>
  4. <cfset FastFoodArray[1] = "French Fries">
  5. <cfset FastFoodArray[2] = "Hot Dogs">
  6. <cfset FastFoodArray[3] = "Fried Clams">
  7. <cfset FastFoodArray[4] = "Thick Shakes">
  8.  
  9.  
  10. <cfloop index="I" from="1" to="5">
  11.  
  12.     <cfset col = "Detail"&I>
  13.  
  14.      <cfset temp = QueryAddColumn(#myQuery#, #col#, "VarChar", FastFoodArray) />
  15. </cfloop>
  16.  
  17.  
  18. <cfdump var="#myQuery#">
Creates cols with Detail1, .. to Detail5

Hope it helps...
Mar 10 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

8
7565
by: Donna Sabol | last post by:
First, I should start by saying I am creating a database to be used by some very impatient, non-computer literate people. It needs to be seameless in it's operation from their point of view. I want them to do as little as possible when they run their reports. I have a crosstab query that displays usage of items for each month. It looks pretty much like this: ITEM DESC UM 12/02 1/03 2/03 3/03 ...ETC. 1 Solution ...
0
2279
by: Penguin | last post by:
Using Access 97, I've created a grading sheet. To save space, the subjects are in vertical columns on a sub-report, like so: Math Spelling Reading N C T A A E U A I C C X M L M C C P B C E U U R E U S R R E
2
2227
by: Amir | last post by:
I really hope someone can explain this behavior. I have spend quite a bit of time and tried a bunch of things, so far nothing has worked. I have a page on which I have a datagrid with template columns. I perform regular expression validations in the EditItemTemplate for the fields that require such validation. The datagrid is inside a div tag to make it scrollable. I have implemented the solution to freeze header for this grid - the...
1
1098
by: Mac via DotNetMonster.com | last post by:
Hi all, I have a datagrid on a form which is not populated until the user enters selection criteria and clicks a button. Rather than have a blank datagrid when the form is displayed, I would like to have the columns headings that are to be displayed actually there. Is this possible? I know how to create a DataGridStyle programatically and add columns, so I added this chunk of code to the "page_load" event and nothing happened. Am I on...
10
9556
by: lorirobn | last post by:
Hi, I have a form with several combo boxes, continuous form format, with record source a query off an Item Table. The fields are Category, Subcategory, and Color. I am displaying descriptions, not ID's, so I have to convert the ID's from various lookup tables. The combo boxes work fine except for subcategory, which is dependent on category. Depending on category, the drop-down box for subcategory will display different items. (for...
27
3775
by: max | last post by:
Hello, I am a newbye, and I'm trying to write a simple application. I have five tables with three columns; all tables are identical; I need to change some data in the first table and let VB updates the same data in all other four tables in the right places. I know it would be possible by using the ForeignKeyConstraint object. I have created the tables using the DataSet Visual Tool and I know it doesn't create any ForeignKeyConstraint obj....
4
1802
by: Techhead | last post by:
I am running into an issue when adding data from multiple columns into one alias: P.ADDR1 + ' - ' + P.CITY + ',' + ' ' + P.STATE AS LOCATION If one of the 3 values is blank, the value LOCATION becomes NULL. How can I inlcude any of the 3 values without LOCATION becoming NULL? Example, if ADDR1 and CITY have values but STATE is blank, I get a NULL statement for LOCATION. I still want it to show ADDR1 and CITY
3
2914
by: Max | last post by:
Hello, I have a datagridview object on my form along with some other controls. When the application runs, the datagridview is populated with data from a database. Although the right number of records is displayed, all the cells in each record are blank. Any idea why? Thanks, Max.
8
5909
by: Paul H | last post by:
I want to base a form on a crosstab query. The query shows statistics for a user defined period. The column headings will look something like this: ClientID Month01 Month02 Month03 etc.. So if the user selects 3 months in the criteria form, there will be 3 (month) column headings, if he selects 6 months, the will be 6 headings.
0
8393
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8598
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8670
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7433
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6223
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5695
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4224
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1809
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.