[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 154
  • Last Modified:

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.
0
kennys
Asked:
kennys
  • 2
  • 2
  • 2
  • +1
1 Solution
 
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
 
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 new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now