Deleteing a record

I am new to VB6 and am writing a program which makes a database from code.

If the user deletes a record from the database all is well but when the last record is deleted, I get a run-time
error "3021" No current record.

My question is :- How do I error trap this.

I want to close the form and return to another form when the last record is deleted.

I repeat, I am new to VB.
kennysAsked:
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.

JasonSantiagoCommented:
You really do not need to error trap this.  You are probably doing something wrong.  When the user deletes the last record you will not get an error unless you try to somehow retrieve the values from the record (which is now deleted).  Why not post your code and I can take a look at what you are doing wrong.
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
JasonSantiagoCommented:
Or you could do something like:

Sub MySub()
on error goto hError:

some code here....
.....
....

  exit sub
hError:
  if err.number = 3021 then
    unload me
  end if
End Sub 'MySub

But this really will only move your logical error to another place, as I said before you are doing something wrong.
0
hesCommented:
Post your code for the delete
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

kennysAuthor Commented:
This is the code


Private Sub cmdDelete_Click()
   
    'delete the selected record
   
    Data1.Recordset.Delete
    Data1.Recordset.MoveNext
   
    'clear the list boxes
    lstBox1.Clear
    lstBox2.Clear
    lstBox3.Clear
    lstBox4.Clear
    lstBox5.Clear
   
    'reload the form
    Call Form_Load

End Sub
0
hesCommented:
Private Sub cmdDelete_Click()
     
    'delete the selected record
     
    Data1.Recordset.Delete
  If not Data1.Recordset.EOF then
    Data1.Recordset.MoveNext
     
    'clear the list boxes
    lstBox1.Clear
    lstBox2.Clear
    lstBox3.Clear
    lstBox4.Clear
    lstBox5.Clear
     
    'reload the form
    Call Form_Load
   Else
     Unload me
   End if
End Sub


0
mmshahCommented:
After you delete the last record move to the next record as you are doing. But immediately after executing MoveNext check for EOF. and if it's EOF you could take the desired action (e.g., unload the form). But just deleting the last row woudl not return you EOF status, you have to move the record pointer to the next record.
I hope this will solve your problem.
0
kennysAuthor Commented:
Many thanks
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
Visual Basic Classic

From novice to tech pro — start learning today.