I am trying to figure out how to pause a code execution until a user clicks a button on a subform.
to make a long story short, a user will click a button on the subform to delete a record, it should then change the source object of the subform to open a new form so they can enter a reason for the deletion. then once they say ok or cancel, change the source object back to the form before and finish executing the code (which is to send an email out). what it is doing now is executing the email code and then going to the reason for deletion subform instead of vice versa. i've tried setting focus to the subform but it still continutes to do the same thing.
Open your Reason form as a Dialog form. Code will not run after the line that initiates the Dialog Form untill the Dialog form is closed. Have the Dialog Form upon closing, to set the Tag property of the calling SubForm to indicate whether or not the Cancel button was selected.
In the SubForm's Command Button OnClick event:
Private Sub SubFormCommandButton_Click()
'Initiate Dialog Form
DoCmd.OpenForm "myReasonFormName", , , , , acDialog
' if the Cancel button was selected in the Reason Form
' then exit this subroutine.
If Me.Tag = "Cancel" then Exit Sub
' otherwise do whatever you want...
In the Reason Form's Cancel button OnClick event:
Private Sub ReasonFormCancelButton_Click()
Form_mySubFormName.Tag = "Cancel"
Self Taught In ALL Environments.....And It Shows!