I'm having an issue using the ADO.Locate function (Using Delphi 7). I've got the following code:
procedure TFrmMain.RzBtnProcessClick(Sender: TObject);
var
WB: IXLSWorkbook;
WS: IXLSWorksheet;
X: Integer;
MillStyle: Integer;
KnitNo: Integer;
CustSKU: String;
begin
if RzBtnEditInputFile.Text = '' then
Application.MessageBox('You Must Select An Input File!','Error',MB_OK)
else if not FileExists(RzBtnEditInputFile.Text) then
Application.MessageBox('Cannot Locate Input File! Please Select A Valid File!','Error',MB_OK)
else
begin
FrmInfo.RzLblInfo.Caption:='Opening AS/400 Connection...';
FrmInfo.Show;
FrmInfo.Refresh;
ADOCnx400.Open;
ADOTblPRICEP.Open;
FrmInfo.RzLblInfo.Caption:='Opening Spreadsheet...';
FrmInfo.Refresh;
WB:=TXLSWorkbook.Create;
WB.Open(RzBtnEditInputFile.Text);
WS:=WB.WorkSheets[1];
FrmInfo.RzLblInfo.Caption:='Processing...';
FrmInfo.Refresh;
for X:=2 to WS.UsedRange.Rows.Count do
begin
if not VarIsNull(WS.Cells[X,3].Value) then
begin
MillStyle:=WS.Cells[X,2].Value;
KnitNo:=WS.Cells[X,3].Value;
SiMain.LogInteger('MillStyle',MillStyle);
SiMain.LogInteger('KnitNo',KnitNo);
ADOTblPRICEP.First;
if ADOTblPRICEP.Locate('DHMSTY;DHKNIT',VarArrayOf([MillStyle,KnitNo]),[]) then
begin
CustSKU:=ADOTblPRICEP.FieldByName('DHCSTY').AsString;
SiMain.LogInteger('RecNo',ADOTblPRICEP.RecNo);
SiMain.LogMessage('** FOUND **');
end
else
begin
CustSKU:='';
SiMain.LogError('** NOT FOUND **');
end;
SiMain.LogString('CustSKU',CustSKU);
WS.Cells[X,5].Value:=CustSKU;
end;
end;
FrmInfo.Close;
WB.Save;
ADOTblPRICEP.Close;
ADOCnx400.Close;
WB.Close;
Application.MessageBox('Finished Processing!','Information',MB_OK);
Close;
end;
end;
The ADOTblPRICEP is filtered on "DHCUST = 309" and filtered set to true.
When I do the ADO.Locate function, it says it finds the MillStyle/KnitNo combination, even though this does NOT exist in the database! Now, what's strange is I can remove the filter and everything seems to work properly! Any ideas?
Thanks in advance!