Thanks for the code. I did some minor tweaking to put just the fields with a value in the where statement.
The where part of this is generating an error. First I will show the query it is based on. Don't get too hung up in the select and from section, this code works with the first cfif condition.
<cfquery datasource='#datasource#' name='GetRecords'>
SELECT tblMain.LN, tblMain.FN, tblAddress.Mail, tlkpDesc_Add.DescAdd, tblAddress.Address1, tblMain.Selected, tblMain.PT, tblMain.SWN, tblMain.TPS, tblMain.UnContacted, tblMain.Metroplex, tlkpCounty.County, tlkpRegion.Region, tlkpCity.City, tlkpState.ST, tblMain.Church, tblMain.MainID, tblAddress.Zip
FROM tlkpState RIGHT JOIN (tlkpDesc_Add RIGHT JOIN (tlkpCounty RIGHT JOIN (tlkpCity RIGHT JOIN ((tblMain LEFT JOIN tlkpRegion ON tblMain.RegionID = tlkpRegion.RegionID) LEFT JOIN tblAddress ON tblMain.MainID = tblAddress.MainID) ON tlkpCity.CityID = tblAddress.CityID) ON tlkpCounty.CountyID = tblMain.CountyID) ON tlkpDesc_Add.DescAddID = tblAddress.DescAddID) ON tlkpState.StateID = tblAddress.StateID
<cfif #len(URL.letter)# EQ 1>
where Left(tblMain.LN,1) = '#url.letter#'
</cfif>
<cfif '#URL.letter#' EQ 'filtered'>
WHERE
<!--- Check that fieldnames exists --->
<CFIF IsDefined("FORM.fieldnames"

>
<!--- Create empty list of processed variables --->
<CFSET fieldnames_processed = "">
<CFSET isfirst = "yes">
<!--- Loop through fieldnames --->
<CFLOOP INDEX="form_element" LIST="#FORM.fieldnames#">
<!--- Try to find current element in list --->
<CFIF #ListFind(#fieldnames_processed#, #form_element#)# IS 0>
<!--- Make fully qualified copy of it (to prevent accessing the wrong field type) --->
<CFSET form_element_qualified = "FORM." & #form_element#>
<cfset formelementvalue = #Evaluate(form_element_qualified)#>
<cfif #len(formelementvalue)# GT 0 AND #formelementvalue# NEQ '0' AND #IsDefined("formelementvalue"

#>
<!--- Output it as part of WHERE statement --->
<CFOUTPUT>
<CFIF #isfirst# EQ 'yes'><cfelse>AND</cfif>
#form_element# LIKE '#Evaluate(form_element_qualified)#'
</CFOUTPUT>
<cfset #isfirst# = "no">
<!--- And add it to the processed list --->
<CFSET fieldnames_processed = #ListAppend(#fieldnames_processed#, #form_element#)#>
<!--- <!--- determine if this is the last item in list, if not add AND to statement --->
<CFIF ListLen(FORM.fieldnames) EQ fieldnames_processed>
<cfelse>
AND
</cfif> --->
</cfif><!-- element has value -->
</CFIF> <!-- current element list -->
</CFLOOP> <!-- fieldname loop -->
</CFIF><!-- fielname exists -->
</cfif>
ORDER BY tblMain.LN, tblMain.FN;
</cfquery>
THis is the error that is generated. Do you see anything wrong with the WHERE statement:
ODBC Error Code = 37000 (Syntax error or access violation)
[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression ' '.
SQL = "SELECT tblMain.LN, tblMain.FN, tblAddress.Mail, tlkpDesc_Add.DescAdd, tblAddress.Address1, tblMain.Selected, tblMain.PT, tblMain.SWN, tblMain.TPS, tblMain.UnContacted, tblMain.Metroplex, tlkpCounty.County, tlkpRegion.Region, tlkpCity.City, tlkpState.ST, tblMain.Church, tblMain.MainID, tblAddress.Zip FROM tlkpState RIGHT JOIN (tlkpDesc_Add RIGHT JOIN (tlkpCounty RIGHT JOIN (tlkpCity RIGHT JOIN ((tblMain LEFT JOIN tlkpRegion ON tblMain.RegionID = tlkpRegion.RegionID) LEFT JOIN tblAddress ON tblMain.MainID = tblAddress.MainID) ON tlkpCity.CityID = tblAddress.CityID) ON tlkpCounty.CountyID = tblMain.CountyID) ON tlkpDesc_Add.DescAddID = tblAddress.DescAddID) ON tlkpState.StateID = tblAddress.StateID WHERE LN LIKE 'scott' ORDER BY tblMain.LN, tblMain.FN;"