We help IT Professionals succeed at work.

Reaching EOF in Access

fvazquez
fvazquez asked
on
300 Views
Last Modified: 2010-04-05
Hi, I have this procedure where I try to delete bills that share the same account number from a Table:

                If ADOTable6.Locate('contract_no',eContract.Text,[]) then
                Begin
                        with ADOTable6 do begin
                        open;
                        first;
                                while not EOF do
                                begin
                                        ADOTable6.Locate('contract_no',eContract.Text,[]);
                                      if  (ADOTable6.FieldByName('contract_no').AsString = eContract.Text) then
                                      begin
                                            ADOTable6.DeleteRecords(arCurrent);
                                      end;
                              next;
                                end; { While}
                        end; {  With }
                        Label15.Caption := 'Deleted';

If the account numbers are in beteween the data, they will be deleted, but if some of them are at the end of the table the last one stays in the table...
Is correct the way I try to delete the bills or is it a better way to delete them? Could anyone please correct my procedure or help me improve it?

Thanks in advance
Francisco Vazquez
                End;
Comment
Watch Question

Top Expert 2007

Commented:
why don't you use sql?

place an adocommand and do:

adocommand.conenction:=theadoconnectionhere;
adocommand.commandtext:='delete from '+tablenamehere+' where contract_no='+quotedstr(eContract.text);
adocommand.execute;
Top Expert 2007

Commented:
btw, if contact_no is not text, then don't do quotedstr :)
Top Expert 2007

Commented:
correction
>if contact_no is not text
if contract_no is number.
dates also must be quotedstred

Author

Commented:
ciuly -> ok let me try with adocommand and contract_no its text yes...

Author

Commented:
ciuly -> I'm having a problem with the query, I already have a connectionstring so I'm using your script like this

adocommand.commandtext:='delete from '+boletas+' where contract_no='+quotedstr(eContract.text);
adocommand.execute;

But I get the following error

[Error] Unit36.pas(180): Undeclared identifier: 'boletas'

How do I declare the tablename?

Top Expert 2007
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Hehehe... my brain didnt register the little change... But I already tested your script and It worked as I wanted! Thanks the points are yours...

Author

Commented:
Super, also it works fastest than the locate....! Thank you Ciuly
Top Expert 2007

Commented:
of course it does:)
no problem ;)

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.