Can't delete record

S

Stuart Grant

I have a form which displays details of each record in text boxes. It has
New, Print and Quit buttons all of which work fine. I added a delete
button with the Button Wizard and made its action Delete Record.

The wizard added this sub

Private Sub cmdDelete_Click()
On Error GoTo Err_cmdDelete_Click

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

Exit_cmdDelete_Click:
Exit Sub

Err_cmdDelete_Click:
MsgBox Err.Description
Resume Exit_cmdDelete_Click

End Sub

When I try to use it, i.e click on the button, after selecting a record, I
get the error message "The command or action "Select Record" isn't available
now", which doesn't make sense to me. The sub goes straight from the first
DoCmd line to the error.

Anybody know what's wrong ?

Stuart
 
B

BruceM

The OP will no doubt be puzzled by a link about hiding the Loading Image
dialog box, as it does not seem to relate to the question. Another
curiosity is your apparent contention that a record can't be deleted in
Access 2003, which is of course not what you were saying.

To the OP, try getting rid of those two DoMenuItem lines of code, and
replacing them with

DoCmd.RunCommand acCmdDeleteRecord

This works with versions of Access from 2000 on, but I don't think it works
with earlier versions. If you have an earlier version I recommend that you
repost with the version information.

Another useful thing is error handling that can provide some more detail.
Instead of MsgBox Err.Description try
MsgBox "Error #" & Err.Number & ", " & Err.Description & " - cmdDelete"

In Access 2002 I believe that attempting to delete a record produces an
error message to the effect that there is no current record, or something
like that. The improved error handling will provide an error number, which
can be useful when searching Google groups or some such for more information
about that, if it occurs. Since I don't know what version of Access you are
using I won't add anything more.
 
S

Stuart Grant

Bruce

Thank you for your advice. I am using Access 2003. I saw once while
looking at the MSDN page on DoCmd that the rather complicated syntax which
the button wizard installed had been replaced by DoCmd.RunCommand
acCmdDelete Record from, I think 2000 or 2003.

Anyway I did as you suggested and also modified the Error Message. When I
click now I get the error message
"Error #2046. The command or action 'Delete Record' isn't available -
cmdDelete"

I really didn't understand Kevin Jameson's message. I didn't know there was
an Access 2004 (I assume 20004 was a typo) and I don't understand why a fix
wouldn't be on a Microsoft Update website.

Stuart
 
B

BruceM

Kevin's message was not relevant. Regarding the error message, does the
form allow deletions, and does it have record locks? Are any controls
locked? I'm not sure if any or all of these may be relevant, but it is a
good place to start.
 
S

Stuart Grant

Bruce

I looked at Google groups for Access for Error 2046 and found pages of
messages, not only, for Delete but many other DoCmd commands. Seems to be a
common problem.

Saw your latest message and checked the form's properties. ALLOW DELETIONS
WAS - NO !!!
How it got that way I do not know. Maybe it is the default.

Anyway problem now solved. Many thanks for your help.

Stuart
 
B

BruceM

You'd think that with thousands of error messages they could come up with a
numbered error just for the Delete situation. Anyhow, glad you got it
working.
 

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