syntax problem?

Results 1 to 2 of 2

Thread: syntax problem?

  1. #1
    Join Date
    Dec 1969

    Default syntax problem?

    Why does this not work? There are no errors but the filter is not taking strEstimator variable as the proper value??<BR><BR>strEstimator is defined above as strEstimator = Request.Form("Estimator")<BR><BR>objRecordset.Filt er = "estimator=" & "&#039;strEstimator&#039;" <BR><BR>While Not objRecordset.EOF<BR> Response.Write objRecordset("ProjectName") & "<BR>"<BR> objRecordset.MoveNext<BR> Wend<BR> <BR> objRecordset.Close<BR> set objRecordset = Nothing<BR><BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default No, just you don't understand strings

    *ANYTHING* that is between " and " is a *LITERAL STRING*.<BR><BR>So in this line:<BR> objRecordset.Filter = "estimator=" & "&#039;strEstimator&#039;" <BR>you have *two* literal strings.<BR> estimator=<BR> &#039;strEstimator&#039;<BR><BR>Those characters will be used *EXACTLY* as you gave them. No substitions whatsoever will be performed.<BR><BR>Since you then concatenate those two strings with the & operator, the effect is to produce<BR> estimator=&#039;strEstimator&#039;<BR>as a single string.<BR><BR>And in SQL (and in a filter like this), everything between &#039; and &#039; is a literal string.<BR><BR>So the filter is perfectly valid. It will look in the recordset for all those records that have an estimator field that contains *EXACTLY* the characters<BR> strEstimator<BR><BR>NO PLACE IN ANY OF THAT CODE did you ask to look for records that matched the contents of the VBS variable that you named strEstimator.<BR><BR>To do that, you would have used:<BR><BR> objRecordset.Filter = "estimator= &#039;" & strEstimator & "&#039;"<BR><BR>But I have to ask why in the world you would do this relatively slow and clumsy process instead of using SQL to get only the relevant records in the first place? <BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts