Subject Re: applyLocate and apostrophe applylocate limit ?
From Dirk C <dirk@C.com>
Date Sun, 18 Aug 2024 11:52:43 +0200
Newsgroups dbase.getting-started

Op 17/08/2024 om 13:22 schreef Mervyn Bick:

Mervyn,

on question about

what's the difference bewteen your solution ( or which influence has the
variable) your shorter way
   bSuccess = oRowset.applyLocate("fieldname = ["+searchString+"]")

and

Case form.keuzedoos_sorteren.value =="firma"
c_Veldf = trim(this.value)
  o_vraagb.Rowset.applyLocate("Name = ["+c_Veldf+"]")

thanks

Dirk,








> On 2024/08/15 21:58, Dirk C wrote:
>> hello to you,
>>
>> when in use findkeynearst : and the name in the field begins with
>> apostrophe :: no problem can find teh value
>>
>> i have a search field using applylocate
>>
>> when i change the combox and put a value in a field beginns with an
>> apostrophe :: applylocate gives an error :  Unallowed phrase/keyword
>> in command:  '
>>
>> when i first give a value and change the combobox it finds the first
>> value beginning with a apostrophe
>>
>> but let's say taking the 4th or whatever value starts with an
>> apostrophe and change the combobox : only get the first value with an
>> apostrophe
>
> applyLocate() moves the row pointer and always starts from the first
> record in the rowset and stops when it finds the first matching record.
> applyLocate() returns true if a match is found and false if not.  If
> this is assigned to a variable it can be used to decide what to do next.
>   If you want to use the same search criteria to move to the next record
> that matches you need to use locateNext().
>
>> even the apostrophe is in the middle of the value: applylocate doesn't
>> accept the '
>>
>> even using the function to replace the ' or strip the '
>
> If you are using .dbf tables and the search field can contain
> apostrophes, instead of the format shown in the example in the help file
>
>    form.rowset.applyLocate( "CITY = '" + form.cityText.value + "'" )
>
> use the following syntax for applyLocate()
>
>     bSuccess = oRowset.applyLocate("fieldname = ["+searchString+"]")
>
> This wraps the search string in square brackets instead of single quotes.
>
> By wrapping the search value in square brackets dBASE will be happy to
> accept apostrophes in the search value.
>
>>
>> c_Veldf = [name='] +trim(this.value)+['] or with quotes
>>
>> Do Case
>>           Case form.keuzedoos_sorteren.value =="firma"
>>             c_Veldf = [name=']+trim(this.value)+[']
>>            ? c_veldf
>>             o_vraagb.rowset.locateOptions = 3
>>               o_vraagb.rowset.beginlocate()
>>                  o_vraagb.rowset.ApplyLocate(c_Veldf)
>>            Case form.keuzedoos_sorteren.value =="postcode"
> .....
>
>>     EndCase
>>
>> thanks for more info
>>
>> Dirk,
>>
>
> You don't say to which object's event handler executes your function so
> I have no idea what object "this" in your code represents.  In the code
> below I'm going to assume that the search value is in an entryfield.
>
> As you want to use different SQL expressions as the argument for
> applyLocate with different search strings depending on the field
> selected in a combobox you are going to have to build the command piece
> by piece and then use the & macro operator to execute it.
>
>
> Try the following.
>
>    o_vraagb.rowset.locateOptions = 3
>    //Set before the Do Case as all options require this and it stays
>    //the same until it is changed elsewhere in the program.
>    Do Case
>      Case form.keuzedoos_sorteren.value =="firma"
> //       o_vraagb.rowset.beginlocate() // See note below
>         cmd =
> 'o_vraagb.rowset.applyLocate("name=['+trim(form.entryfield1.value)+']")'
>       //?cmd //Uncomment to see command
>       &cmd
>     Case form.keuzedoos_sorteren.value =="postcode"
> //       o_vraagb.rowset.beginlocate() // See note below
>         cmd =
> 'o_vraagb.rowset.applyLocate("plz=['+trim(form.entryfield1.value)+']")'
>       //?cmd //Uncomment to see command
>       &cmd
> .......
>
> o_vraagb.rowset.beginlocate() is only needed if you are using the
> "locate by form" option i.e the user enters a search value in an
> entryfield datalinked to the search field.
>
> Mervyn.