dpokerbear
asked on
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_frmSessionAttendanc e.Form.Rec ordset.Del ete
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
Private Sub cmdSubDeleteRecord_Click()
On Error GoTo Err_MyProc
Me.sub_frmSessionAttendanc
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
ASKER
JDettman, the subform is bound to a table and yes, the On Delete Event I am checking is in the subform.
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.
JimD.
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.
If you don't see your code, then something is messed up.
JimD.
ASKER
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?
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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
<<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>.se tfocus
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.
You need to make sure the focus is on the subform.
Me.<subformcontrolName>.se
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.
ASKER
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.
<<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.
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.
JimD.
ASKER
Hi Jim,
How did you go with the test?
Cheers
D
How did you go with the test?
Cheers
D
ASKER
Thanks for your help.
Sorry, I lost track of this. I'll try and do this today.
JimD.
JimD.
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.