Locating a Part Location based on part number

I'm tring to find a Part Location based on a Part number thats entered in a standard Edit Box. Here's what I have:

procedure TMainForm.FindPartLocationClick(Sender: TObject);
begin
  DataModuleForm.PartID.Open; // Make sure its open first
  PartNumber.Text := DataModuleForm.PartIDPartNumber.AsString; //An Edit Box to perform the locate
  DataModuleform.PartID.Locate('Location', Edit1.Text ,[]);
  ShowMessage('Part Number is stored at  ' + DataModuleForm.PartIDPartLocation.AsString);
  DataModuleForm.PartID.Close; // Now lets close it
end;

But it always retuns the same Part Location no matter what Part Number I enter. Any one have a clue to what I'm doing wrong?


routerboy309Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kretzschmarCommented:
hi routerboy,

try to use a local var

procedure TMainForm.FindPartLocationClick(Sender: TObject);
var s : String;
begin
  s := Edit1.Text;
  DataModuleForm.PartID.Open; // Make sure its open first
  PartNumber.Text := DataModuleForm.PartIDPartNumber.AsString;
  //An Edit Box to perform the locate
  DataModuleform.PartID.Locate('Location', s ,[]);
  ShowMessage('Part Number is stored at  ' + DataModuleForm.PartIDPartLocation.AsString);
  DataModuleForm.PartID.Close; // Now lets close it
end;

meikl
0
RBertoraCommented:
I think you must build an index on Location too!, and I'm not sure if you need the final parameter to be [lopartialkey]....

Rob ;-)
0
routerboy309Author Commented:
Indexing did the trick. (Big Smile). Is adding this type of control to the DBGrid basically the same method? (where in the events do I add the code?. I added it to OnCellClick and it always go to the last entry) RBertora - please send the grade sheet.
0
RBertoraCommented:
Thankyou,
Rob ;-)

P.S. Add what control? and what code are you now talking about? sorry didn't follow the last bit..
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
routerboy309Author Commented:
RBertora

I added the code to a DBGrid (on CellClick event). I wanted to use either the TButton or if a user clicks on the DBGrid, the edit box would update the location. But something with the Grid or my code (more so) is causing the cursor to jump to the either the last record or the first record and is failing to update the field....Weird. I have remove all instances and it still happens. Wonder if its the table opening and closing?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.