• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 957
  • Last Modified:

How to trigger Form events?

If I use the code below (button code) to delete a record in a subform data sheet, then the code I have in Form - On Delete Event doesn't get triggered. How can I make Form events trigger while using the code below?

Private Sub cmdSubDeleteRecord_Click()

On Error GoTo Err_MyProc

   Me.sub_frmSessionAttendance.Form.Recordset.Delete

Exit_MyProc:
        'Deassign all objects.
       
        Exit Sub

Err_MyProc:
        'Error handler here
        Select Case (Err.Number)
            Case 3021
                MsgBox "No record is selected."
            Case Else
               MsgBox (Err.Description)
        End Select
   
        Resume Exit_MyProc
End Sub
0
dpokerbear
Asked:
dpokerbear
  • 7
  • 6
1 Solution
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
<<On Delete Event doesn't get triggered.>>
The subform needs to be bound to a recordsource and make sure it's the On Delete event of the subform that your checking, not the main form.
JimD.
 
0
 
dpokerbearAuthor Commented:
JDettman, the subform is bound to a table and yes, the On Delete Event I am checking is in the subform.
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
Put a STOP at the top of the event code.  Then execute.  Do you get the STOP?  If not, your VBA project may be corrupt.  A /Decompile or better yet, an import to a new DB container may be required.
JimD.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
One other check you can make; open the subform, then the property sheet, click the event tab, scroll down to the OnDelete, make sure it says "[Event Procedure]" and then click the builder button to the right (...)
If you don't see your code, then something is messed up.
JimD.
 
0
 
dpokerbearAuthor Commented:
I tried all of that already. I put breakpoints in all my form events and no, they don't get triggered if the buttons are used with the code, which I provided sample above.

On property sheets it does say [Event Procedure] etc...

I think it's something to do with the code which is written in the button above. Perhaps form events don't get triggered if code is acting directly on the recordset of that form? What do you think?
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
I didn't catch that before. Try:
DoCmd.RunCommand acCmdDeleteRecord
 in place of your delete statment.
JimD.
0
 
dpokerbearAuthor Commented:
Ahhh, that's great. Thanks Jim.

Just a quick addition additional question to that. How would I apply that command if deleting a record in a subform though?

For example:

Me.frmClass.Form.Recordset.Delete
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
<<How would I apply that command if deleting a record in a subform though?>>
You need to make sure the focus is on the subform.

Me.<subformcontrolName>.setfocus
DoCmd.RunCommand acCmdDeleteRecord
and this is just for testing. I still don't understand why your delete on the forms recordset is not triggering the delete, unless I'm forgetting something.
JimD.

0
 
dpokerbearAuthor Commented:
thanks for that.

<<I still don't understand why your delete on the forms recordset is not triggering the delete, unless I'm forgetting something.>>

I am not sure about this one either. Are you saying that if you create a form which is bound to a table and then try using the same code as I am using for my buttons, yours actually triggers a Delete Event?

If it's doing it for you, then, I would like to do more testing and try and resolve this issue before closing off this task.

Please let me know. Thanks.
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
I haven't tested it here myself, but will try latter today.  I'm relying on memory; if a form is bound (has a controlsource set) then anything I do to that recordset in either code or via the menu should be triggering a form event.
JimD.
0
 
dpokerbearAuthor Commented:
Hi Jim,

How did you go with the test?

Cheers
D
0
 
dpokerbearAuthor Commented:
Thanks for your help.
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
Sorry, I lost track of this.  I'll try and do this today.
JimD.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now