Link to home
Start Free TrialLog in
Avatar of routerboy309
routerboy309

asked on

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?


Avatar of kretzschmar
kretzschmar
Flag of Germany image

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
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 ;-)
Avatar of routerboy309
routerboy309

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of RBertora
RBertora
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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?