• On Load vs. On Open

    Author
    Topic
    #460592

    What’s the difference between the two properties?
    Do Open events occur before Load events?
    Armstrong

    Viewing 0 reply threads
    Author
    Replies
    • #1165293

      The On Open event of a form occurs almost immediately when a form is opened, before the records have been loaded into memory.
      The On Open event procedure has an argument Cancel that you can set to True if you want to abort the opening of the form. For example:

      Code:
      Private Sub Form_Open(Cancel As Integer)
        If Not CurrentProject.AllForms("frmOther").IsLoaded Then
      	Cancel = True
        End If
      End Sub

      The On Load event occurs later, when the records are being loaded into memory.
      The On Load event procedure has no arguments, so you can’t cancel it.

      If you need to be able to cancel opening the report, use the On Open event.
      If you need to do something with records in the form, use the On Load event because the On Open event occurs too early for that.

      • #1165295

        Hi HansV,
        First, thanks for your generosity to provide the complete VBA code.
        Nonetheless, I pray for more clarity from you.

        Questions:
        >The On Open event of a form occurs almost immediately when a form is opened,..
        For “almost immediately when,” does it mean immediately before OR after when a form is being opened?
        Collaterally, does it also imply the properties (such as name of a control) are NOT available in the Open event?

        >The On Load event occurs later, when the records are being loaded into memory.
        Does it mean that the On Load event is occurring while the records are being loaded?

        Thanks.

        Armstrong

        • #1165299

          According to the Access help:
          [indent]The Open event occurs when a form is opened, but before the first record is displayed.
          The Load event occurs when a form is opened and its records are displayed.[/indent]The Open event does not occur before the form is opened. That would be impossible.
          So the names of controls etc. are available in the Open event procedure.
          But the values of controls might not be available yet, since the Open event occurs before the records are being displayed.

    Viewing 0 reply threads
    Reply To: On Load vs. On Open

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: