Delete Selected Record

  • Thread starter Thread starter C.R. Houk
  • Start date Start date
C

C.R. Houk

I have been struggling with this for a while so I hope
someone can help. I have a form with an unbound field
that lets me type in the Primary Key number for a record.
The record data then appears in a subform. On the main
form I have a delete key with the Onclick code as follows:

Focus = DelQuery_subform

DoCmd.RunCommand acCmdDeleteRecord

I want the record which is visible in the subform to be
deleted from the inventory table. I seemed to have it
working, but then I came back the next day and no longer
seems to. Any help in this will be greatly appreciated as
I am currently looking for the nearest wall to bang my
head against.

C.R. Houk
charles.houk2<nospam>@charleston.af.mil
 
Put this code in the OnClick event:

Me!NameOfSubformControl.SetFocus
Me!NameOfAFieldINSubform.SetFocus
DoCmd.RunCommand acCmdDeleteRecord
Me!NameOfDeleteButton.SetFocus
 
Hmm, okay trying this but...maybe it's the sleep
deprivation, but it's not working.
My code is now

Me!NibsNumber.setfocus
DoCmd.RunCommand acCmdDeleteRecord
Me!Command5.SetFocus

I get the message you are about to delete 1 record.
I select Yes
The record remains in the screen and in the table.
 
Your commanding officer would be upset if he saw this; you didn't follow
directions. You left the first line of code out! When you go from a main form to
a subform, you first must set focus to the subform control and then set focus to
a control on the subform.

Steve
PC Datasheet
 
I had the first command in the line originally, but it
kept giving me the error
Access can not find the field referred to in your
expression.
 
Open the main form in design view. Select the subform control. Open properties,
go to the Other tab and see what the name is. Put that name in where I use
"NameOfSubformControl" in
Me!NameOfSubformControl.SetFocus.

Steve
 
Back
Top