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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
RBertoraConnect With a Mentor Commented:
Thankyou,
Rob ;-)

P.S. Add what control? and what code are you now talking about? sorry didn't follow the last bit..
0
 
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
 
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
All Courses

From novice to tech pro — start learning today.