Subject |
Re: applyLocate and apostrophe applylocate limit ? |
From |
Mervyn Bick <invalid@invalid.invalid> |
Date |
Sun, 18 Aug 2024 15:37:52 +0200 |
Newsgroups |
dbase.getting-started |
On 2024/08/18 11:52, Dirk C wrote:
> 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+"]")
That was simply meant to point out that, although the help file gives an
example, it is not usable in all cases.
Using the applyLocate() example in the help file i.e
form.rowset.applyLocate( "CITY = '" + form.cityText.value + "'" )
If the value in form.cityText.value was O'Grady the code would evaluate to
form.rowset.applyLocate( "CITY = 'O'Grady'" ) which would cause an
error. dBASE sees "CITY = 'O'" and doesn't know what to do with Grady'
By using the syntax I suggested the code would evaluate to
form.rowset.applyLocate( "CITY = [O'Grady]" ) which dBASE can handle.
This does not apply to ADOrowsets where one would need to use an
"escape" character ahead of the apostrophe as "proper" SQL requires
literal strings to be delimited using single quotes.
>
> and
>
> Case form.keuzedoos_sorteren.value =="firma"
> c_Veldf = trim(this.value)
> o_vraagb.Rowset.applyLocate("Name = ["+c_Veldf+"]")
>
The object represented by "this" depends on how the function was
executed but if this.value contains the name you want to locate then
your code should work. The important thing is that c_Veldf is delimited
with square brackets in the SQL expression used as the argument for
applyLocate(). This means that if there's an apostrophe in the value it
won't cause a problem.
There is no real need to use a macro as I did in the example but using
it does mean you will be able to display the actual command to check for
errors if it doesn't work.
Mervyn.
|
|