I am getting the error - "Complex object types cannot be converted to simple values" when I try to use two variables in my CFMAIL tag. Here is what I am doing (using CF7 on WinXP and MS Access 2000):
1. I am running a query that looks for users names and email addresses based on a drop down menu selected on a previous page (using a session variable defined in the Application.cfm page). I am also setting the query and the email addresses to a variable with the CFIF part of the code. That query looks like this:
**************************
<cfif isDefined("session.School"
)>
<cfquery name="GetEmail_schools" datasource="#DataSource#">
SELECT StudentID, First, Last, Email, School
FROM data
WHERE School = '#session.School#'
</cfquery>
<cfset userquery="#GetEmail_schoo
ls#">
<cfset useremail="#GetEmail_schoo
ls.Email#"
>
<cfelseif isDefined("session.Program
")>
<cfquery name="GetEmail_programs" datasource="#DataSource#">
SELECT StudentID, First, Last, Email, Program
FROM data
WHERE Program = '#session.Program#'
</cfquery>
<cfset userquery="GetEmail_progra
ms">
<cfset useremail="GetEmail_progra
ms.Email">
<cfelseif isDefined("session.Teacher
")>
<cfquery name="GetEmail_teachers" datasource="#DataSource#">
SELECT StudentID, First, Last, Email, Teacher
FROM data
WHERE Teacher = '#session.Teacher#'
</cfquery>
<cfset userquery="GetEmail_teache
rs">
<cfset useremail="GetEmail_teache
rs.Email">
<cfelseif isDefined("session.Gender"
)>
<cfquery name="GetEmail_gender" datasource="#DataSource#">
SELECT StudentID, First, Last, Email, Gender
FROM data
WHERE Gender = '#session.Gender#'
</cfquery>
<cfset userquery="GetEmail_gender
">
<cfset useremail="GetEmail_gender
.Email">
<cfelseif isDefined("session.SpecSer
v")>
<cfquery name="GetEmail_specserv" datasource="#DataSource#">
SELECT StudentID, First, Last, Email, Spec_Services
FROM data
WHERE Spec_Services = #session.SpecServ#
</cfquery>
<cfset userquery="GetEmail_specse
rv">
<cfset useremail="GetEmail_specse
rv.Email">
<cfelseif isDefined("session.Year")>
<cfquery name="GetEmail_year" datasource="#DataSource#">
SELECT StudentID, First, Last, Email, Year
FROM data
WHERE Year = #session.Year#
</cfquery>
<cfset userquery="GetEmail_year">
<cfset useremail="#GetEmail_year.
Email#">
</cfif>
**************************
***
2. I am trying to send an email to each user returned in the query using this code:
<cftry>
<cfmail
Type="HTML"
query="#userquery#"
To="#useremail#"
From="admin@server.com"
Subject="#form.EmailSubjec
t#"
SERVER="localhost"
PORT="25"
>
<p>#First#,</p>
#Form.Message#
<cfsilent>
<cfif FORM.attachment_1 neq "">
<cfmailparam file="#attachment_1#">
</cfif>
</cfsilent>
</cfmail>
<cfcatch type="any">
<cfoutput>
<h1>Survey</h1>
<span class="style1">Sorry...we cannot process your request at this time. Please try again later. If you are getting this error repeatedly, <br />
Please email our <a href="mailto:webmaster@ser
ver.com" title="Webmaster Email">Webmaster</a>.</spa
n>
<cfabort>
</cfoutput>
</cfcatch>
</cftry>
************************
3. When I run this code I get this error:
Complex object types cannot be converted to simple values.
The expression has requested a variable or an intermediate expression result as a simple value, however, the result cannot be converted to a simple value. Simple values are strings, numbers, boolean values, and date/time values. Queries, arrays, and COM objects are examples of complex values.
The most likely cause of the error is that you are trying to use a complex value as a simple one. For example, you might be trying to use a query variable in a <CFIF> tag. This was possible in ColdFusion 2.0 but creates an error in later versions.
The error occurred in C:\CTE\sendemail_3.cfm: line 63
61 : <cfmail
62 : Type="HTML"
63 : query="#userquery#"
64 : To="#useremail#"
65 : From="admin@server.com"
I understand that a query is a complex data type so I have some understanding of why the error is happening, but the question is how do I use a variable in both the CFMAIL Query= and CFMAIL To= attributes?
thanks,
Ken
Start Free Trial