Results 1 to 5 of 5
  1. #1
    Radwar is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Posts
    2

    Trigger subform events

    Hi to all,
    This is my first post and I learnt access programming by myself so please be patient if I don't use the correct terminology.
    I've made a form where all controls (including the form itself) are managed by a class module and everything works fine even form and controls events.
    Problems starts when I open this form in another one as subform.
    I already know that all references changes and this was not a big issue for all the controls and their events in subform.


    Different situation for the form events.
    This works good in the standalone form:

    Private whitevents mForm as Access.Form
    mForm.OnCurrent = "[Event Procedure]"

    I've tried something like this :

    Private whitevents mForm as Access.Subform

    mForm.Form.OnCurrent = "[Event Procedure]"

    This, and other fancy attempts not work or get an error so anyone knows a way to correctly refer to subform events?

  2. #2
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    I think your referencing method is overly complicated and wrong.
    Perhaps explain WHAT you are trying to do instead of HOW you are trying it, like:

    I have a main form named X with a subform named Y. I want to...
    Last edited by davegri; 09-29-2018 at 08:45 AM. Reason: extra

  3. #3
    Radwar is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Posts
    2
    Thanks for the answer.
    I have a class that trigger some forms and control events. What I want is the same behavior when the form is a subform.
    The problem is forms and subforms are obviously different so what I'm looking for is a way or method to correctly reference the form to trigger its events.

  4. #4
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    The problem is forms and subforms are obviously different so what I'm looking for is a way or method to correctly reference the form to trigger its events.
    Still think you are approaching this in an overly complicated fashion. Why do you have a user class module for the form? Forms have a native class module of their own.
    Again, what is the broad description of WHAT you are trying to do with the forms, the end result you are trying to accomplish, not the method to do it.

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Whatever the reason, I'll assume WhiteEvents (as you posted) is really WithEvents since you say the code works if you open the form directly. Perhaps all you need now is the syntax for referring to subform controls and events
    referencing CONTROLS on subform:

    Code:
    [Forms]![Main form name]![subform control name].[Form]![control name on subform]
    e.g. 
    [Forms]![frmNP]![subNPfrm].[Form]![txtNPno]
    frmNP is main form name
    subNPfrm is name of subform control on frmNP
    txtNPno is the textbox control name

    referencing subform PROPERTY (e.g. recordset property such as Recordcount):
    Code:
    Forms("MainFormName").Controls("subformControlName").Form.Recordset.Recordcount
    e.g. Forms("frmWhoUsesVendor").Controls("subWhoUsesVendor").Form.Recordsource
    or perhaps
    Code:
    Forms!frmWhoUsesVendor")!subWhoUsesVendor.Form!Recordsource
    I found that I had issues with the latter, so I used the long syntax and it worked. Perhaps Recordsource isn't a valid reference to the Form keyword/object.

    NOTE: subformControlName DOES NOT REFER TO THE SUBFORM NAME ALTHOUGH IT MAY BE THE SAME.

    The above does not apply when navigation form is used. You also have to understand that subforms load before a main form, which might actually be your problem.

    EDIT - have to admit I've never taken your approach. Would have to research to see why, outside of maybe creating an error handling class. There must be better reasons than that? As for that example, one could simply write a public function and call it from anywhere in the project without having to make it a class, so that's why that example seems like a poor reason for creating the class. Or is it to make the class available to any code project?
    Last edited by Micron; 09-29-2018 at 12:06 PM. Reason: added questions
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 12-07-2014, 01:15 PM
  2. Subform events do not seem to be firing
    By mantooth29 in forum Programming
    Replies: 2
    Last Post: 12-12-2013, 03:13 PM
  3. Replies: 2
    Last Post: 07-24-2011, 08:50 PM
  4. Can't Find Subform Events
    By vdanelia in forum Forms
    Replies: 4
    Last Post: 02-28-2011, 02:23 PM
  5. Trigger subform event
    By tuna in forum Forms
    Replies: 0
    Last Post: 05-09-2010, 06:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums