Capture Button Click Event From Parent Form

crhodus

Registered User.
Local time
Today, 11:55
Joined
Mar 16, 2001
Messages
257
Hi Everyone,

I have a form, named MyParent, that contains an Add/Edit and a Cancel button on it. The form also contains a subform, named MySubForm.

In the MySubForm Form_BeforeUpdate event, I have added a few edit checks which launch a MessageBox that contains the appropriate error message. I have also added a MsgBox in the BeforeUpdate that asking the user if they want to save their changes.

Here is my problem:
If the user adds or edits a records and then clicks on the Cancel button, btnCancel, because they do not want to save their changes, my edit checks from the BeforeUpdate event fire off and prevent the user from canceling their changes.

Is there a way to capture the Cancel button click event from MyParent in the MySubForm code?

My thoughts were to try something like this in the MySubForm BeforeUpdate event:

Code:
If Me.[MyParent].Field!btnCancel.Click = True Then
''// Cancel changes made to record.
Me.Undo
Else
''// Execute Edit Checks.
End If

Thanks,
Crhodus
 
I have figured out a way to prevent my edit check from executing by moving and modifying some of my code in the subForm.

I'm still curious to know if you can capture the button click event from the parent form from within the subForm. Does anyone know if this is possible?

Thanks,
Crhodus
 
I have figured out a way to prevent my edit check from executing by moving and modifying some of my code in the subForm.

I'm still curious to know if you can capture the button click event from the parent form from within the subForm. Does anyone know if this is possible?

Thanks,
Crhodus

Don't think it's possible in the way you're trying...VBA doesn't really have event listeners like many programming languages.

You could create a public or global variable and on the Cancel button click event set that to true, then on the before update event if the variable is true run your extra code then reset the variable to false.
 

Users who are viewing this thread

Back
Top Bottom