delete record error 2046

T

tonyak

When I delete the last record in the database, I receive the following error:

Run-time error 2026. The command or action 'recordsgotonew' isn't available
now.

I created a delete button and here is the code I am using to delete the record

Private Sub Delete_Record_Click()
Recordset.Delete
DoCmd.RunCommand acCmdRecordsGoToNew
Me.Requery
End Sub
 
K

Ken Snell [MVP]

Why do you want to create a new record and then do a requery right after it?
This will move you away from that "new" record and it won't be in focus at
that point.

As for why you get the error, there can be any number of causes. Sometimes,
it's because the delete action causes an event to occur on a control or the
form, and code in an event procedure tied to that event errors and stops the
RunCommand action from being able to occur. Or, the form in which you're
wanting to run this code has its AllowAdditions property set to No and won't
allow the creation of a new record. Or ... well, without knowing more about
your form and its setup, further speculation is probably not helpful.

You'll need to give us a lot more details about your setup and wishes.
 
T

tonyak

After I delete a record, I would like the program to allow the user to add a
new record.

I do not receive this error message while deleting any record other than if
I am deleting the last record in the database.
 
K

Ken Snell [MVP]

When you delete the last record in the form's Recordset, the form no longer
can display any data and it essentially is "empty", and there is no current
record for it to move from. In this case, you may need to change your
approach/design for what you want to achieve. Perhaps you should consider
allowing a user to click a button if he/she wants to add a new record
instead of trying to do it automatically? Or to go to a new form to add a
record?

We don't have very much information about your form's setup, what you're
using for its RecordSource, etc., so it's difficult to make additional
suggestions at the moment.
--

Ken Snell
<MS ACCESS MVP>
 

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