Skip to Content
VB & VBA in a Nutshell: The Language
book

VB & VBA in a Nutshell: The Language

by Paul Lomax
October 1998
Intermediate to advanced
656 pages
16h 10m
English
O'Reilly Media, Inc.
Content preview from VB & VBA in a Nutshell: The Language
Unload Statement

Syntax

Unload object

object

Use: Required

Data Type: Object

A form or control loaded at runtime.

Description

Removes a form or (in Visual Basic) a dynamically created member of a control array from memory.

Rules at a Glance

  • Only controls added to a control array at runtime can be removed from memory using the Unload statement. Those controls added to a form at design time can't be unloaded individually.

  • When a form, the form's Query_Unload event is fired. Once its event handler has executed, the form's Form_Unload event is fired.

  • When object is an MDI form, the following is the order of events:

    1. MDI form QueryUnload event

    2. All loaded child forms' QueryUnload events

    3. All loaded child forms' Form_Unload events

    4. MDI form Form_Unload event

Programming Tips and Gotchas

  • You can prevent a form from unloading by setting the Cancel argument to True in a QueryUnload or Form_Unload event procedure. Cancel is a parameter passed by reference to both the QueryUnload and the Unload events.

  • When you unload a form from within the form's code, you should use the Me keyword to refer to the form. This makes your code more readable, as the following snippet shows:

    Unload Me
  • Microsoft recommends that forms should be unloaded only in the Click event of a CommandButton or menu control. Calling the Unload statement in other event handlers can have undesirable side effects and cause general protection faults (GPFs).

  • You can also bring your code for loading and unloading forms in line with the latest ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Programming Excel with VBA and .NET

Programming Excel with VBA and .NET

Jeff Webb, Steve Saunders

Publisher Resources

ISBN: 1565923588Catalog PageErrata