Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WHAT THE Eff is Missing!?! 1

Status
Not open for further replies.

shadyness

MIS
Dec 21, 2001
89
US

"Error Type:
Microsoft VBScript compilation (0x800A03EE)
Expected ')'

I was developing a simple html form that fed an asp page with three values to limit the SQL string, but I keep getting the above error. There are two date fields (from a text input) and a name (select option). For some reason the SQL String that is requesting the data from an Access BE, is incorrect for the title section called "SUBREGION". If I take it out, the the date fields are requested fine and the page will write HTML fine and display the data limited by the date fields. If I replace the Subregion variable with a literal value then it also works fine. I dont know what I am missing in my attempt to parse this variable. HELP!!

Here is the html:

<html>
<head>
<title>.: Index Pricing Database for Example :.</title>
</head>
<body bgcolor=&quot;#666666&quot;>
<form action = &quot;navigant_2_1.asp&quot; method=&quot;GET&quot;>
<table width=&quot;471&quot; height=&quot;36&quot; bgcolor=&quot;#FFFFFF&quot;>
<tr>
<td width=&quot;272&quot; height=&quot;32&quot; bgcolor=&quot;#000000&quot;>
<b><font face=&quot;Arial&quot; size=&quot;3&quot; color=&quot;#FFFFFF&quot;>Choose WECC Sub Region</b>
</font>
</td>
<td width=&quot;185&quot; ALIGN=&quot;CENTER&quot;>
<select name=&quot;sub_region&quot;><OPTION VALUE=&quot;1&quot;>COB<OPTION VALUE=&quot;2&quot;>FOUR CORNERS
<OPTION VALUE=&quot;3&quot;>MID COLUMBIA<OPTION VALUE=&quot;4&quot;>MIDWAY<OPTION VALUE=&quot;5&quot;>NORTH PATH 15
<OPTION VALUE=&quot;6&quot;>PALO VERDE<OPTION VALUE=&quot;7&quot;>SOUTH PATH 15
</td>
</tr>
<tr>
<td width=&quot;272&quot; height=&quot;32&quot; bgcolor=&quot;#000000&quot;>
<b><font face=&quot;Arial&quot; size=&quot;3&quot; color=&quot;#FFFFFF&quot;>Enter Starting Date<BR><font size =&quot;1&quot;>(MM/DD/YYYY format):</b>
</font>
</td>
<td width=&quot;185&quot; height=&quot;32&quot; bgcolor=&quot;#FFFFFF&quot; align=&quot;center&quot; valign=&quot;middle&quot;>
<input name=&quot;start_date&quot;
size=&quot;25&quot; maxlength=&quot;50&quot;>
</td>
</tr>
<tr>
<td width=&quot;272&quot; height=&quot;32&quot; bgcolor=&quot;#000000&quot;>
<b><font face=&quot;Arial&quot; size=&quot;3&quot; color=&quot;#FFFFFF&quot;>Enter Ending Date<BR><font size =&quot;1&quot;>(MM/DD/YYYY format):</b>
</font>
</td>
<td width=&quot;185&quot; height=&quot;32&quot; bgcolor=&quot;#FFFFFF&quot; align=&quot;center&quot; valign=&quot;middle&quot;>
<input name=&quot;end_date&quot;
size=&quot;25&quot; maxlength=&quot;50&quot;>
</td>
</tr>
</table>
<table bgcolor=&quot;#333333&quot; align=&quot;left&quot; valign=&quot;middle&quot; width=&quot;471&quot; height=&quot;49&quot;>
<tr align=&quot;CENTER&quot; valign=&quot;middle&quot;>
<td height=&quot;50%&quot;>
<input type=&quot;submit&quot; value=&quot;Submit&quot;><br>
</td>
</tr>
<tr align=&quot;CENTER&quot;>
<td height=&quot;50%&quot;>
<font face=&quot;Veranda&quot; color=&quot;#FFFFFF&quot; size=&quot;2&quot;>Please Click For Your Answer</font>
</tr>
</form>
</table>

*******************************************
Here is the ASP
*******************************************
<%@ language=&quot;vbscript&quot; %>
<% Option Explicit %>

<%
'Dimension Var's, ya bastards!

Dim Date_1 ' Beginning Date
Dim Date_2 ' End Date
Dim SubRegionNum ' Area # to limit to
Dim SubRegionStr ' Sting of Region title
Dim cnnGetRows ' ADO connection
Dim rstGetRows ' ADO recordset
Dim strDBPath ' Path to our Access DB (*.mdb) file
Dim arrDBData ' Array that we dump all the data into

' Temp vars to speed up looping over the array
Dim I, J
Dim iRecFirst, iRecLast
Dim iFieldFirst, iFieldLast

'Get the previous values from the user html
Date_1 = TRIM( Request(&quot;start_date&quot;))
Date_2 = TRIM( Request(&quot;end_date&quot;))
SubRegionNum = TRIM( Request(&quot;sub_region&quot;))

'Set the possible hard coded options
IF SubRegionNum =&quot;1&quot; THEN
SubRegionStr = &quot;COB&quot;
END IF
IF SubRegionNum =&quot;2&quot; THEN
SubRegionStr = &quot;FOUR CORNERS&quot;
END IF
IF SubRegionNum =&quot;3&quot; THEN
SubRegionStr = &quot;MID COLUMBIA&quot;
END IF
IF SubRegionNum =&quot;4&quot; THEN
SubRegionStr = &quot;MIDWAY&quot;
END IF
IF SubRegionNum =&quot;5&quot; THEN
SubRegionStr = &quot;NORTH PATH 15&quot;
END IF
IF SubRegionNum =&quot;6&quot; THEN
SubRegionStr = &quot;PALO VERDE&quot;
END IF
IF SubRegionNum =&quot;7&quot; THEN
SubRegionStr = &quot;SOUTH PATH 15&quot;
END IF

' MapPath to our mdb file's physical path.
strDBPath = Server.MapPath(&quot;navigant_database.mdb&quot;)

' Create a Connection using OLE DB
Set cnnGetRows = Server.CreateObject(&quot;ADODB.Connection&quot;)

' Open the Access Base
cnnGetRows.Open &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot; & strDBPath & &quot;;&quot;

' Here is the SQL String Causing all of the probs:
Set rstGetRows = cnnGetRows.Execute (&quot;SELECT tblPrices.DATE, tblPrices.SECTOR, tblPrices.REGION, tblPrices.SUBREGION, tblPrices.T, tblPrices.INDEX_PRICE &quot; &_
&quot;FROM tblPrices &quot; &_
&quot;GROUP BY tblPrices.DATE, tblPrices.SECTOR, tblPrices.REGION, tblPrices.SUBREGION, tblPrices.T, tblPrices.INDEX_PRICE &quot; &_
'Here is the problem line right here:
&quot;WHERE tblPrices.SUBREGION =&quot; '&quot;&SubRegionStr&&quot;' &quot; &_
&quot;AND tblPrices.DATE Between #&quot;&Date_1&&quot;# AND #&quot;&Date_2&&quot;# &quot; &_
&quot;ORDER BY tblPrices.DATE;&quot;)

arrDBData = rstGetRows.GetRows()

' Close our recordset and connection and dispose of the objects.
rstGetRows.Close
Set rstGetRows = Nothing
cnnGetRows.Close
Set cnnGetRows = Nothing

iRecFirst = LBound(arrDBData, 2)
iRecLast = UBound(arrDBData, 2)
iFieldFirst = LBound(arrDBData, 1)
iFieldLast = UBound(arrDBData, 1)

' Display a table of the data in the array.
%>
<html>
<head>
<title>.: Search Results for Price Index :.</title>
</head>
<body bgcolor=&quot;#ffffff&quot;>
<table border=&quot;1&quot; bgcolor=&quot;#EDEDED&quot;>
<%

Response.Write &quot;<b><i>This is the Data for</i> &quot; &SubRegion& &quot;</b>&quot;
' Loop through the records (second dimension of the array)
For I = iRecFirst To iRecLast
' A table row for each record
Response.Write &quot;<tr>&quot; & vbCrLf

' Loop through the fields (first dimension of the array)
For J = iFieldFirst To iFieldLast
' A table cell for each field
Response.Write vbTab & &quot;<td>&quot; & arrDBData(J, I) & &quot;</td>&quot; & vbCrLf
Next ' J

Response.Write &quot;</tr>&quot; & vbCrLf
Next ' I

%>
</table>

 
I'm not sure what the problem is but try writing your SQL to a variable and then display that variable out to the page to make sure you are getting the correct SQL

Then you can execute the variable:

strSQL = &quot;SELECT tblPrices.DATE, tblPrices.SECTOR, &quot;
strSQL = strSQL + &quot;tblPrices.REGION, tblPrices.SUBREGION,&quot; strSQL = strSQL + &quot;tblPrices.T, tblPrices.INDEX_PRICE &quot;
strSQL = strSQL + &quot;FROM tblPrices GROUP BY tblPrices.DATE, &quot;
strSQL = strSQL + &quot;tblPrices.SECTOR, tblPrices.REGION, &quot;
strSQL = strSQL + &quot;tblPrices.SUBREGION, tblPrices.T, &quot;
strSQL = strSQL + &quot;tblPrices.INDEX_PRICE &quot;
strSQL = strSQL + &quot;WHERE tblPrices.SUBREGION= &quot;
strSQL = strSQL + &quot;'&quot; & SubRegionStr & &quot;' &quot;
strSQL = strSQL + &quot;AND tblPrices.DATE Between #&quot;
strSQL = strSQL + Date_1 & &quot;# AND #&quot; & Date_2 &&quot;# &quot;
strSQL = strSQL + &quot;ORDER BY tblPrices.DATE;&quot;
response.write &quot;<BR>SQL: &quot; & strSQL
'Now execute the SQL in Access and see what you get
'If it works then do the next line
Set rstGetRows = cnnGetRows.Execute(strSQL)

Hope that helps...
mwa
 
Thanks. I know how to write out my SQl strings, but I didn't really think to try it out. The server is having issues with the quotes I think. becuase it will pass the value SUBREGION=COB, in the query string but not &quot;COB&quot; as access is going to need it to do the search.
 
try your SQL statement like this
Set rstGetRows = cnnGetRows.Execute (&quot;SELECT tblPrices.DATE, tblPrices.SECTOR, tblPrices.REGION, tblPrices.SUBREGION, tblPrices.T, tblPrices.INDEX_PRICE &quot; &_
&quot;FROM tblPrices &quot; &_
&quot;GROUP BY tblPrices.DATE, tblPrices.SECTOR, tblPrices.REGION, tblPrices.SUBREGION, tblPrices.T, tblPrices.INDEX_PRICE &quot; &_
'Here is the problem line right here:
&quot;WHERE tblPrices.SUBREGION ='&quot;&SubRegionStr&&quot;' &_
&quot;AND tblPrices.DATE Between #&quot;&Date_1&&quot;# AND #&quot;&Date_2&&quot;# &quot; &_
&quot;ORDER BY tblPrices.DATE;&quot;)

The only change is removing the &quot; from around SubRegionStr.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top