Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Filling listbox programmatically
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00173149
Message ID:
00173151
Views:
36
>Hello all,
> I'm encountering a syntax error while trying to populate a listbox with an SQL statement. The SQL looks like this:
>
>.cmbRangeFrom.rowsource = "SELECT costcen.dptname FROM costcen WHERE ( &lcWhereClause ) ORDER BY costcen.dptname into cursor ccfrom"
>
>The Whereclause variable is built up programmatically from a for loop based upon the values in a global array. The for loop looks like this:
>
>FOR lnLooper = 1 to THISFORM.listcount
> SELECT areaprop
> LOCATE for (areaprop->areaname= gaDataAreaArray(lnLooper))
> lcAreaId = areaprop->areapro_id
> lcWhereClause = lcWhereClause + iif(lnLooper = 1, "", " OR ") + ;
> "costcen.area_id = " + "'" + lcAreaId + "'"
>ENDFOR
>
>But there's a catch. If the number of elements OR'd together in the where clause is less than or equal to five, this select works fine. However, when the number is greater than five, I encounter the syntax error. Any ideas?
>
>Thanks!

There are two problems here. Firstly, SELECT does not like too many ORs. I guess you may better generate INLIST() function list to use within lcWhereClause. Another problem is that it's not reliable to use lcWhereClause (local variable I guess) as integral part of rowsource expression, because it might be evaluated by VFP in many points of your application when the variable can get out of scope and be perceived as .F. You may base your listbox on cursor.
Edward Pikman
Independent Consultant
Previous
Reply
Map
View

Click here to load this message in the networking platform