[AccessD] Call SubForm Event Procedure

A.D.TEJPAL adtp at airtelbroadband.in
Fri Dec 29 11:40:03 CST 2006


Mark,

    The target procedure in a form or subform, that you wish to call externally should be made public.

    In sample code given at (A) & (B) below, if CmdMainMaster located on the parent form is clicked, it will execute the click event of CmdSubSlave on the subform. Similarly, if CmdSubMaster located on the subform is clicked, it will execute the click event of CmdMainSlave on the main form.

    Important:
        (a) While calling a subform's public subroutine from code in main form's module, use of  Form. qualifier is essential. On the other hand, while calling main form's public subroutine from code in subform's module, use of  Form. qualifier is to be AVOIDED.
        (b) Similar precaution is applicable while triggering the events on a form or its subform, via code located in an external form's module, for example (F_Main is the name of main form while SF_Sub is the name of subform control acting as container for the subform):
        (1) Call main form's public event via code in external form:
        Forms("F_Main").CmdMainSlave_Click
        (2) Call subform's public event via code in external form:
        Forms("F_Main")("SF_Sub").Form.CmdSubSlave_Click


    My sample db named FormsSubformsReference might also be of interest to you. It is available at Rogers Access Library (other developers library). Link - http://www.rogersaccesslibrary.com/OtherLibraries.asp#Tejpal,A.D.

Best wishes,
A.D.Tejpal
---------------

A) Code in main form's module
(SF_Sub is the name of subform control
acting as container for the subform)
============================
Private Sub CmdMainMaster_Click()
    Me.SF_Sub.Form.CmdSubSlave_Click
End Sub

Public Sub CmdMainSlave_Click()
    MsgBox "CmdMainSlave"
End Sub
============================

B) Code in subform's module
============================
Private Sub CmdSubMaster_Click()
    Me.Parent.CmdMainSlave_Click
End Sub

Public Sub CmdSubSlave_Click()
    MsgBox "CmdSubSlave"
End Sub
============================

  ----- Original Message ----- 
  From: Mark A Matte 
  To: accessd at databaseadvisors.com 
  Sent: Friday, December 29, 2006 03:07
  Subject: [AccessD] Call SubForm Event Procedure


  Hello All,

  I have an OnCurrent event on a subform.  Can I call, or cause to fire from the main form.

  Thanks,

  Mark A. Matte


More information about the AccessD mailing list