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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Locate is not working in AdoTable

Status
Not open for further replies.

beltijs

Programmer
Sep 11, 2003
25
AR
I'm doing a simple locate in an ado table and the locate returns True but it doesn't move to the right record. this is my code:

for i:= 0 to db_grid.Columns.Count -1 do
dm_ppp.tmyadotable.First;
busqueda := trim(db_grid.Columns.FieldName);
if dm_ppp.Tmyadotable.Locate('campo',busqueda,[]) then
{some code}
else
ShowMessage('Error');
end;

this is driven me crazy, i've tried:
- changing the locate options
- closing and opening the table
- changing and taking off all indexes of the table

i dont know what else to do, and im sure it has a very simple solution, but i can't find it.

Help? Thanks
 
I don't know if you typed that in or you copy and pasted it but it appears as if you're missing a 'begin' on your for loop.

Other than that your code looks like mine when I've used Locate successfully. I'm using D6 Enterprise, how about you?
 
The begin is missing in the paste i do when i write the question, in the code it's rigth.
I'm using D6 Enterprise mi self.
And i have made Locate million times. Thats why i'm so lost.

(The logic of the locate it's fine, obviusly, in the field 'campo' of mi adotable is the value i'm looking for).

 
Ok, next thing I'd be looking for is the actual field names. I've seen some crazy things happen when a field name is a reserved word for the database engine. ie. having a field called Text. Is your program failing on the first field, or on one further into your loop? What's the field called?
 
I've tried what you suggested. I've my Delphi 6 in English and my Access in Spanish, so de field name 'Campo' could by a problem, so i change it, but it still doesn't work.
The search is working right in the first loop, the other ones are the problem, some times find it, and some times dont.
Here the code complete:


with dm_ppp.Tplanilla do
begin
if Locate('pl_orden',1,[]) then
txt_query := FieldByName('pl_query').asstring
else
begin
ShowMessage('No se pudo actualizar el campo');
abort;
end;
for i:= 0 to db_grid.Columns.Count -1 do
begin
First;
busqueda := trim(db_grid.Columns.FieldName);
if Locate('pl_campo',busqueda,[]) then
begin
Edit;
FieldValues['pl_ancho'] := db_grid.Columns.Width;
FieldValues['pl_orden'] := i+1;
if i = 0 then
FieldValues['pl_query'] := txt_query
else
FieldValues['pl_query'] := '';
Post;
end

else
ShowMessage('Error al grabar seteos de columnas');
end;
end;

The idea is that there is a table called 'Planilla', in these tables i keep some information about how to show some dbgrid, which columns to show, in which order and their width. When the user exits the form where the dbgrid is, i want to keep the values of the order of the column and the widths the user gives to them.

 
Well, i solve the problem, i make the search based in two columns, something like this:

" if Locate('pl_pantalla;pl_campo',vararrayof([pantalla,busqueda]),[]) then "

Now is working fine. Lets say that i solve the problem but i didn't answer the question.

Thanks Griffyn for your help ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top