Error deleting record - acCmdDeleteRecord isn't available

G

Guest

I have a form and subform combination for entering two related records, an
Inventory item Master definition and an Inventory item sub definition. The
master information is on the main form and the sub definition is on the
subform. I have coded logic to delete the master record that is
automatically written by Access when the user tabs from the main form into
the subform IN THE EVENT that the user enters no information into the subform
and exits from/closes the main form using the exit button I've provided.
When I test this code, I get error 2046 "The command or action
acCmdDeleteRecord isn't available now." and I cannot figure out why I am
getting this error. My code to do this delete, which is in the click event
of my main form's Exit button, is:
Private Sub cmdExitInvMaster_Click()
On Error GoTo Err_cmdExitInvMaster_Click

'If Hardware specific record (i.e PC, Router, etc.) not created and Inv
Class is Hardware, delete Inv Master
If Not HWMasterExists And IMInvClassID = 1 Then
Me.IMInvDescr.SetFocus
DoCmd.RunCommand acCmdDeleteRecord
End If
DoCmd.Close

Exit_cmdExitInvMaster_Click:
Exit Sub

Err_cmdExitInvMaster_Click:
MsgBox Err.Description
Resume Exit_cmdExitInvMaster_Click

End Sub

Note: HWMasterExists is a function that tests to see if a record was created
in the subform, and seems to be working fine. Record source for main form is
a query over the associate InventoryMaster table. Please pardon if this is
posted twice -my first posting, and having a bit of difficulty getting the
hang of it. Any help will be greatly appreciated.
 
O

OldPro

I have a form and subform combination for entering two related records, an
Inventory item Master definition and an Inventory item sub definition. The
master information is on the main form and the sub definition is on the
subform. I have coded logic to delete the master record that is
automatically written by Access when the user tabs from the main form into
the subform IN THE EVENT that the user enters no information into the subform
and exits from/closes the main form using the exit button I've provided.

Let me get this straight, you have two separate tables - a master and
a detail - and you want to delete a record in the master if no
information exists in the detail. Can I assume that the record was
just added?
When I test this code, I get error 2046 "The command or action
acCmdDeleteRecord isn't available now." and I cannot figure out why I am
getting this error. My code to do this delete, which is in the click event
of my main form's Exit button, is:
Private Sub cmdExitInvMaster_Click()
On Error GoTo Err_cmdExitInvMaster_Click

'If Hardware specific record (i.e PC, Router, etc.) not created and Inv
Class is Hardware, delete Inv Master
If Not HWMasterExists And IMInvClassID = 1 Then
Me.IMInvDescr.SetFocus
DoCmd.RunCommand acCmdDeleteRecord
End If
DoCmd.Close

Exit_cmdExitInvMaster_Click:
Exit Sub

Err_cmdExitInvMaster_Click:
MsgBox Err.Description
Resume Exit_cmdExitInvMaster_Click

End Sub

Note: HWMasterExists is a function that tests to see if a record was created
in the subform, and seems to be working fine. Record source for main form is
a query over the associate InventoryMaster table. Please pardon if this is
posted twice -my first posting, and having a bit of difficulty getting the
hang of it. Any help will be greatly appreciated.

If the record in the master table hasn't been officially added yet,
then setting Cancel to true in the BeforeUpdate event may work.
 
G

Guest

OldPro said:
Let me get this straight, you have two separate tables - a master and
a detail - and you want to delete a record in the master if no
information exists in the detail. Can I assume that the record was
just added?


If the record in the master table hasn't been officially added yet,
then setting Cancel to true in the BeforeUpdate event may work.

Yes, your assumption that the record in the master table was just added is
correct. My understanding is that Access adds the record to the master table
once the user tabs into the subform in order to maintain referential
integrity between the parent/master and child tables. That being the case, I
want to avoid having this master record sitting in the table if the user
decides to exit from the form without having entered the associated detail.

As to setting Cancel to true in the BeforeUpdate event if the record hasn't
been officially added, all I know so far (I'm pretty new to Access and VB) is
what I just stated regarding Access's default action when tabbing from a main
form to a subform (which I believe I learned on this site); so, I would have
to assume that the record has been officially added.

Thanks for your response.
 

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