Search code examples
vbams-access

Triggering an event in subform control in Access using VBA


I wanted to trigger an after update event in the subform using vba from the parent form.

In the subform I have:

Private Sub USER_AfterUpdate()
  'After update code
End sub

The subforms name in my parent form is subForm2

So from my main form I am doing:

Call subForm2.Form.USER_AfterUpdate

However, I get

Application-defined or object defined error

I wanted to target the last user field in my subform but I do not mind running an after update event on all of the user field in the sub form.


Solution

  • Either make the function Public:

    Public Sub USER_AfterUpdate()
      'After update code
    End Sub
    

    or create a separate function to call:

    Private Sub USER_AfterUpdate()
        UserAfterUpdate
    End sub
    
    Public Sub UserAfterUpdate()
      'After update code
    End sub
    

    and then call this (UserAfterUpdate) from the main form.

    You may have to use the extended syntax:

    Call procedures in a subform or subreport