UserForm Object, UserForms Collection
Description
A UserForm object is a window or dialog box that makes up part of an application's user interface.
The UserForms collection is a collection whose elements represent each loaded UserForm in an application. The UserForms collection has a Count property, an Item property, and an Add method. Count specifies the number of elements in the collection; Item (the default member) specifies a specific collection member; and Add places a new UserForm element in the collection.
Syntax
UserForm
UserForms[.Item](index)
The placeholder index represents an integer with a range from 0 to UserForms.Count – 1. Item is the default member of the UserForms collection and need not be specified.
Remarks
You can use the UserForms collection to iterate through all loaded user forms in an application. It identifies an intrinsic global variable named UserForms. You can pass UserForms(index) to a function whose argument is specified as a UserForm class.
User forms have properties that determine appearance such as position, size, and color; and aspects of their behavior.
User forms can also respond to events initiated by a user or triggered by the system. For example, you can write code in the Initialize event procedure of the UserForm to initialize module-level variables before the UserForm is displayed.
In addition to properties and events, you can use methods to manipulate user forms using code. For example, you can use the Move method to change the location and size of a UserForm.
When designing user forms, set the BorderStyle property to define borders, and set the Caption property to put text in the title bar. In code, you can use the Hide and Show methods to make a UserForm invisible or visible at run time.
UserForm is an Object data type. You can declare variables as type UserForm before setting them to an instance of a type of UserForm declared at design time. Similarly, you can pass an argument to a procedure as type UserForm. You can create multiple instances of user forms in code by using the New keyword in Dim, Set, and Static statements.
You can access the collection of controls on a UserForm using the Controls collection. For example, to hide all the controls on a UserForm, use code similar to the following:
For Each Control in UserForm1.Controls
Control.Visible = False
Next Control
Note You can't use the UserForm object and UserForms collection in Microsoft Access, even though it's part of the Visual Basic for Applications type library. The properties, methods, and events listed below for this object are part of the Forms type library.
Properties
ActiveControl property, BackColor property, BorderColor property, BorderStyle property, CanPaste property, CanRedo property, CanUndo property, Caption property, Cycle property, DrawBuffer property, Enabled property, Font object, ForeColor property, Height, Width properties, HelpContextID property, InsideHeight, InsideWidth properties, KeepScrollBarsVisible property, Left, Top properties, MouseIcon property, MousePointer property, Name property, Picture property, PictureAlignment property, PictureSizeMode property, PictureTiling property, ScrollBars property, ScrollHeight, ScrollWidth properties, ScrollLeft, ScrollTop properties, SpecialEffect property, StartUpPosition property, Tag property, VerticalScrollbarSide property, Visible property, WhatsThisButton property, WhatsThisHelp property, Zoom property.
Methods
Copy method, Cut method, Hide method, Move method, Paste method, PrintForm method, RedoAction method, Repaint method, Scroll method, SetDefaultTabOrder method, Show method, UndoAction method, WhatsThisMode method.
Events
Activate, Deactivate events, AddControl event, BeforeDragOver event, BeforeDropOrPaste event, Click event, DblClick event, Error event, KeyDown, KeyUp events, KeyPress event, Layout event, MouseDown, MouseUp events, MouseMove event, RemoveControl event, Scroll event, Terminate Event, Zoom event.
See Also
Unload statement.