Wavequation said:
I have a routine I'd like to run when a form closes, that associated with a
command button on another form. Can I trigger the event associated with
the
command button by using VBA attached to the onclose event of the first
form?
Only if you make the event procedure from for the command button Public
instead of Private. By default, event procedures are Private, as in this
example Sub header:
Private Sub cmdMyButton_Click()
Before you can call this button's event procedure from another form, you
have to change "Private" to "Public":
Public Sub cmdMyButton_Click()
After that change has been made, you can call the procedure from another
form, but you need to qualify it with a reference to the form containing the
procedure (which must be open). For example, if cmdMyButton is on form
"frmButtonForm", and you want to call it from the Close event of form
"frmClosing", then -- provided the event procedure is declared Public as
above -- you can do it with code like this in frmClosing:
'----- start of example code -----
Private Sub Form_Close()
If CurrentProject.AllForms("frmButtonForm").IsLoaded Then
Call Forms!frmButtonForm.cmdMyButtonClick
End If
End Sub
'----- end of example code -----
Depending on your application's logic, you may or may not need the test to
see whether frmButtonForm is open before attempting to call its
cmdMyButtonClick procedure.