cannot delete last record with code

J

JC

If I load a form whose resource is an empty table, I get a
blank record that I can enter data into.
If my table has only one record in it and I delete it, I
get error 3021.

I am using docmd.runcommand accmddeleterecord to delete
the records on the form.
What do I have to do in order to delete that one and only
record without an error?
Once I do that, then I can code it to go into "add mode".

My code is below.

Private Sub butIDel_Click()
Dim Response As Integer

Response = MsgBox("Are you sure you want to delete this
record?" & vbCrLf & "You will NOT be able to get this data
back!", vbYesNo, "Warning!")
If Response = vbYes Then
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand (acCmdDeleteRecord)
DoCmd.GoToRecord , , acLast
DoCmd.SetWarnings True
End If
Me.PartNum.SetFocus
End Sub
 
J

JC

Thanks Terry - works great.
- jc -
-----Original Message-----
In your code you are using GoToRecord,,acLast when there are no records. Wrap
the GotoRecord line in an If where you check the number of records and only
GoToRecord if there are records
Terry


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top