Design Outlook Workgroup Solutions

With Microsoft Outlook, you can create a variety of workgroup solutions and forms. You can create workgroup solutions by using custom views in a public folder,. You can also create simple forms with no programming involved or create advanced forms by using custom controls, properties, and VBScript. You can also use another Office program to create a form.

There are four basic approaches to creating Outlook solutions. You can use existing items, such as tasks or appointment items, put the items in a public folder, and assign a view to the folder. This method gives you an instant workgroup solution without writing any code. Another method is to modify an existing item, such as a contact or mail message, by adding additional pages and fields. With this method, you can extend the use of the item by adding the fields and pages you need without writing any code. To create advanced forms, you can use the Control Toolbox and VBScript to access properties, events, methods, and objects within Outlook. You can also use Office document forms, such as using Microsoft Excel to create an expense report.

What method do you want to use?

Create an instant workgroup solution using public folders

Create custom forms by using VBScript


Overview of a Typical Folder-based Solution

When used with Microsoft Exchange Server, Microsoft Outlook provides groupware capabilities that allow more than one person to work on the same data. Even without using these capabilities, however, you can still customize Outlook folders for your personal use or to create a solution that other people in your organization can use.

If you’re planning to build a groupware solution, you should consider first working with Outlook to develop a single-user solution. Since a groupware solution is often as simple as placing a custom form in a Microsoft Exchange public folder, learning the basics of building a folder-based personal forms solutions will be fully applicable to developing solutions in public folders.

Whether it’s in one of your personal folders or in a Microsoft Exchange public folder, putting together an Outlook solution typically involves the following steps:

  1. Decide which type of folder and/or form to customize.
  2. Open a new form and customize it to suit your needs.
  3. Publish the form to the folder so that it’s available only for use in that folder.
  4. Set the custom form as the default form for the folder. This will ensure that when you create new items for use in this folder they’ll be based on the custom form you created.
  5. If you have any existing items in the folder, update these items so they will use the new form when they’re opened.

Note If you plan to use a custom form in a folder, you should create the custom form before creating any items based on the form. This will ensure that all the items in the folder use the same set of fields.

If you need to update the form after having created some items in the folder, follow these steps:

  1. Open a new, blank item based on your custom form.
  2. Update the form to suit your needs.
  3. Republish the form to the folder using the same name.


Using views to create a solution

Although custom forms provide a powerful way to work with data in a folder, you can also customize Microsoft Outlook to a great extent simply by creating a view that suits your needs. In some cases, depending on how you want to work with Outlook, you can use a custom view instead of a custom form to enter and modify data.

Entering data in a view is usually done be selecting one of the Outlook table views, wherein each row contains one item in the folder and each column represents a field associated with an item. You can select the fields that Outlook displays, and you can also enter or change the contents of fields directly in the table view. This allows you to quickly modify items, even those that contain custom fields.

To allow field editing in a view

  1. Click View, point to Current View, then click Customize Current View.
  2. Click Other Settings.
  3. Select Allow in-cell editing.

Editing items in a table view lets you keep track of custom data, view multiple items at the same time, enter data into an item without having to open the item, and avoid having to create a custom form.


Change the form used by existing items in a folder

In some cases you may need to change the form associated with items that are already in a folder. This is often necessary after importing items, or if you create a custom form after you have already created items based on a standard Microsoft Outlook form.

The Message Class field cannot be directly changed using the Outlook user interface, but you can use VBScript, Visual Basic, or Visual Basic for Applications to change the Message Class field.

The following Automation code can be used as a basis for developing your own solution. This code assumes that the name of the new form is MyForm. It will change all contacts in your default contacts folder so that they will use MyForm.

Sub ChangeMessageClass()
Set olApp = New Outlook.Application
Set olNS = olApp.GetNameSpace("MAPI")
Set ContactsFolder = _
    olNS.GetDefaultFolder(olFolderContacts)
Set ContactItems = ContactsFolder.Items
For Each Itm in ContactItems
   If Itm.MessageClass <> "IPM.Contact.MyForm" Then
      Itm.MessageClass = "IPM.Contact.MyForm"
      Itm.Save
   End If
Next
End Sub

Note If you want to use a folder other than a default folder, use the Folders collection object to refer to any folder that is available in your Folder List.


Create custom forms by using VBScript

Microsoft VBScript is a subset of Visual Basic for Applications. You can use VBScript to create procedures that control Microsoft Outlook folders, objects, items, and properties. VBScript in Outlook requires a special object syntax that has some differences from referencing objects in Visual Basic for Applications.

Learn about the Outlook object model.

You can choose the Outlook item on which to base your custom form.

You can extend Outlook forms by using custom controls from the Control Toolbox. Outlook forms can use most of the properties and methods that come with the controls. Since controls cannot store values, to store the value you need to bind the control to an Outlook field.

The Outlook object browser displays the classes, properties, methods, events, and constants available from the Outlook object library. The object browser lets you view and use objects in the Microsoft Script Editor and obtain information about the syntax for using the object.

Learn about viewing and using the object browser.

The Microsoft Script Debugger provides you with a comprehensive debugging environment for testing and correcting errors in the VBScript code for your forms.

Learn about the Script Debugger.


Using contact item selector fields

You can customize a contact form using specially bound controls that display dialog boxes that let users change fields in the item.

Most of these controls are available directly from the Field Chooser. The following lists these controls.

Address Selector | Address Selected
E-mail Selector | E-mail Selected
Phone x Selector | Phone x Selected

To use these fields on a contact form page, open the form in design mode and then use the Field Chooser to drag the field onto the page. This will automatically create the appropriate controls and labels on the page.

You can also bind a standard control button to one of three special contact dialog boxes:

  • Categories
  • Check Address
  • Check Name

To bind a contact-item dialog box to a button

  1. In design mode, drag a command button from the Control Toolbox to a page on the form.
  2. Right-click the command button, click Properties, and then click Value.
  3. Click Choose Field, point to All Contact fields, and then click the name of the dialog box you want to bind the button to.

Note You can also use the same method to bind the Categories dialog box to a button on the form of any item except a mail message. However, the Categories dialog box is listed only under All contact fields, regardless of the type of form being designed.


Outlook fields and equivalent properties

Name of field in Outlook Field Chooser | Name of equivalent Outlook object model property
% Complete | PercentComplete
Account | Account
Actual Work | ActualWork
Address Selected | N/A
Address Selector | N/A
All Day Event | AllDayEvent
Anniversary | Anniversary
Assigned | DelegationState
Assistant's Name | AssistantName
Assistant's Phone | AssistantTelephoneNumber
Attachment | Attachments
Bcc | BCC
Billing Information | BillingInformation
Birthday | Birthday
Business Address | BusinessAddress
Business Address City | BusinessAddressCity
Business Address Country | BusinessAddressCountry
Business Address PO Box | BusinessAddressPostOfficeBox
Business Address Postal Code | BusinessAddressPostalCode
Business Address State | BusinessAddressState
Business Address Street | BusinessAddressStreet
Business Fax | BusinessFaxNumber
Business Home Page | BusinessHomePage
Business Phone | BusinessTelephoneNumber
Business Phone 2 | Business2TelephoneNumber
Callback | CallbackTelephoneNumber
Car Phone | CarTelephoneNumber
Categories | Categories
Cc | CC
Changed By | N/A
Children | Children
City | HomeAddressCity
Color | Color
Company | Companies
Company | CompanyName
Company Main Phone | CompanyMainTelephoneNumber
Complete | Complete
Computer Network Name | ComputerNetworkName
Contact | FormDescription .ContactName
Contacts | Links
Content | Body
Conversation | ConversationTopic
Country | HomeAddressCountry
Created | CreationTime
Customer ID | CustomerID
Date Completed | DateCompleted
Defer until | DeferredDeliveryTime
Department | Department
Distribution List Name | DLName
Do Not AutoArchive | NoAging
Download State | N/A
Due By | FlagDueBy
Due Date | DueDate
Duration | Duration
E-mail | Email1Address
E-mail 2 | Email2Address
E-mail 3 | Email3Address
E-mail Selected | N/A
E-mail Selector | N/A
End | End
Entry Type | Type
Expires | ExpiryTime
File As | FileAs
First Name | FirstName
Flag Status | FlagStatus
Follow-up Flag | FlagRequest
From | SentOnBehalfOfName
FTP Site | FTPSite
Full Name | FullName
Gender | Gender
Government ID Number | GovernmentIDNumber
Have Replies Sent To | ReplyRecipientNames
Hobbies | Hobby
Home Address | HomeAddress
Home Address City | HomeAddressCity
Home Address Country | HomeAddressCountry
Home Address PO Box | HomeAddressPostOfficeBox
Home Address Postal Code | HomeAddressPostalCode
Home Address State | HomeAddressState
Home Address Street | HomeAddressStreet
Home Fax | HomeFaxNumber
Home Phone | HomeTelephoneNumber
Home Phone 2 | Home2TelephoneNumber
Icon | FormDescription .Icon
Importance | Importance
In Folder | Parent
Initials | Initials
Internet Free Busy Address | InternetFreeBusyAddress
ISDN | ISDNNumber
Job Title | JobTitle
Journal | Journal
Junk E-Mail Type | N/A
Language | Language
Last Name | LastName
Last Saved Time | N/A
Location | Location
Mailing Address | MailingAddress
Mailing Address Indicator | N/A
Manager's Name | ManagerName
Meeting Status | MeetingStatus
Message | Body
Message Class | MessageClass
Message Flag | FlagStatus
Middle Name | MiddleName
Mileage | Mileage
Mobile Phone | MobileTelephoneNumber
Modified | LastModificationTime
Nickname | NickName
Notes | Body
Office Location | OfficeLocation
Optional Attendees | OptionalAttendees
Organizational ID Number | OrganizationalIDNumber
Organizer | Organizer
Other Address | OtherAddress
Other Address City | OtherAddressCity
Other Address Country | OtherAddressCountry
Other Address PO Box | OtherAddressPostOfficeBox
Other Address Postal Code | OtherAddressPostalCode
Other Address State | OtherAddressState
Other Address Street | OtherAddressStreet
Other Fax | OtherFaxNumber
Other Phone | OtherTelephoneNumber
Outlook Internal Version | OutlookInternalVersion
Outlook Version | OutlookVersion
Owner | Owner
Pager | PagerNumber
Personal Home Page | PersonalHomePage
Phone n Selected | N/A
Phone n Selector | N/A
PO Box | HomeAddressPostOfficeBox
Primary Phone | PrimaryTelephoneNumber
Priority | Importance
Private | Sensitivity
Profession | Profession
Radio Phone | RadioTelephoneNumber
Read | UnRead
Received | ReceivedTime
Recurrence | RecurrencePattern .RecurrenceType
Recurrence Pattern | N/A
Recurrence Range End | RecurrencePattern .PatternEndDate
Recurrence Range Start | RecurrencePattern .PatternStartDate
Recurring | IsRecurring
Referred By | ReferredBy
Remind Beforehand | ReminderMinutesBeforeStart
Reminder | ReminderSet
Reminder Override Default | ReminderOverrideDefault
Reminder Sound | ReminderPlaySound
Reminder Sound File | ReminderSoundFile
Reminder Time | ReminderTime
Reminder Topic | N/A
Remote Status | RemoteStatus
RequestStatus | N/A
Requested By | N/A
Required Attendess | RequiredAttendees
Resources | Resources
Response Requested | ResponseRequested
Retrieval Time | N/A
Role | Role
Schedule+ Priority | SchedulePlusPriority
Send Plain Text Only | N/A
Sensitivity | Sensitivity
Sent | SentOn
Show Time As | BusyStatus
Size | Size
Spouse | Spouse
Start | Start
Start Date | StartDate
State | HomeAddressState
Status | Status
Street Address | HomeAddressStreet
Subject | Subject
Suffix | Suffix
Team Task | TeamTask
Telex | TelexNumber
Title | Title
To | To
Total Work | TotalWork
Tracking Status | TrackingStatus
TTY/TTDD Phone | TTYTDDTelephoneNumber
User Field 1 | User1
User Field 2 | User2
User Field 3 | User3
User Field 4 | User4
Web Page | WebPage
ZIP/Postal Code | HomeAddressPostalCode


Ways to protect sensitive information

Many applications use data that is for authorized users only. The following list suggests ways you can protect sensitive information in a form. Note however, that the fields associated with a form can still be exposed in a view.

  • Write code that makes a control (and its data) invisible to unauthorized users. To identify a particular user in code, use the following code.

    Application.GetNameSpace("MAPI").CurrentUser

    The Visible property makes a control visible or invisible.

  • Write code that sets the control foreground and background to the same color when unauthorized users run the application. This hides the information from unauthorized users. The ForeColor and BackColor properties determine the foreground color and the background color.
  • Disable the control when unauthorized users run the application. The Enabled property determines when a control is disabled.
  • Require a password to alter a form.
  • Require a password for access to the application or a specific control. You can use placeholders as the user types each character. The PasswordChar property defines placeholder characters.
  • If the form only appears in a public folder, you can set permissions for the folder to determine who can open the form.

Note Using passwords or any other techniques listed above can improve the security of your application, but these methods do not guarantee the prevention of unauthorized access to your data.


Use z-order to layer controls

  1. Select the controls you want to reposition in the z-order.
  2. On the Layout menu, point to Order, and then click one of the following.
    Click | To move control
    Bring to Front | To the top of the z-order.
    Send to Back | To the bottom of the z-order.
    Bring Forward | Up one position in the z-order.
    Send Backward | Down one position in the z-order.

Notes

  • You can't Undo or Redo layering commands, such as Send to Back or Bring to Front.
  • If the form includes any ListBox, Frame, or MultiPage controls, these controls automatically move as close as possible to the top of the stack. For example, applying Send Backward to a ListBox, Frame, or MultiPage control moves the control below other ListBox, Frame, or MultiPage controls, but does not move the control below any other type of control in the stack. Similarly, applying Bring Forward to a control other than a ListBox, Frame, or MultiPage control moves the control closer to the top of the stack, but does not move the control above any ListBox, Frame, or MultiPage control in the stack.

    Visually, this means that if a ListBox, Frame, or MultiPage control and any other Microsoft Forms controls are in the same location on a form, the ListBox, Frame, or MultiPage control always appears on top of the other control(s). If a ListBox, Frame, or MultiPage control is in the same place as another ListBox, Frame, or MultiPage control, the z-order of the controls determines which control appears on top of the other.


Using Visual Basic with Outlook

You can use Visual Basic to customize and extend Microsoft Outlook. Outlook allows you to control Outlook by using Visual Basic, Visual Basic for Applications and VBScript. Which you use depends on what you want your program to do.

Visual Basic is a full-featured programming language you can use to create stand-alone applications or dynamic-link libraries (DLLs) that extend other applications. Visual Basic for Applications is a subset of Visual Basic that is run within an application to extend its capabilities. VBScript is a simplified version of Visual Basic for Applications and is run within an Outlook item. In all cases, these programming languages control Outlook through its object model.

Learn about the Outlook object model.

If you want to create a separate application that accesses data stored by Outlook and uses Outlook to send and receive messages, use Visual Basic to create the application (you can also use other programming languages, such as C++, to control Outlook through its object model). You can also use Visual Basic to create a DLL that can extend Outlook as a COM add-in.

You use Visual Basic for Applications in one of two ways: You can use Visual Basic for Applications in other applications (such as Microsoft Excel or Microsoft Word) to automate Outlook, or you can use Visual Basic for Applications within Outlook to control Outlook. If you expect your users to be using another application most of the time, and you want to give them the ability to send a message using Outlook or to access information stored by Outlook, write Visual Basic for Applications programs in that application that control Outlook through the Outlook object model. If, on the other hand, you want to write Visual Basic code that customizes how Outlook works (like a macro), use Visual Basic for Applications within Outlook.

You can extend the functionality of Outlook forms by using VBScript. VBScript programs are stored within a form. Because the program code is contained within the form, it can be sent with an item to another user. An important consideration in choosing which kind of the Visual Basic programming language you will use is the type of events you want your program to respond to. Because VBScript code is associated with a particular item, code that responds to events in specific items (such as when a particular item is opened or a value in a field is changed) is easiest to write using VBScript. If, on the other hand, you want your program to respond to events that occur in the application, in Windows Explorer, in folders, or in all items, then you should write your program using Visual Basic or Visual Basic for Applications.

Code written for Visual Basic or Visual Basic for Applications often does not work in VBScript without modification. For example, you must replace all built-in constants written in Visual Basic for Applications with the literal numeric values of those constants in VBScript. And VBScript uses only the Variant data type.

Learn about constants and variables in VBScript.

In Outlook Visual Basic for Applications and VBScript, when you reference the Application object to use CreateObject or GetObject, you simply use Application. For example, the following code displays the Tasks folder:

Set olMAPI = Application.GetNameSpace("MAPI")
olMAPI.GetDefaultFolder(13).Display

In Visual Basic or Visual Basic for Applications in other applications, you must explicitly create the Application object:

Set myOlApp = CreateObject("Outlook.Application")
Set olMAPI = myOlApp.GetNameSpace("MAPI")
olMAPI.GetDefaultFolder(olFolderTasks).Display


About using VBScript in Outlook

Microsoft VBScript is a powerful scripting language based on Microsoft Visual Basic that enables you to control objects, folders, forms, items, and controls within a form. For example, you can change properties and values of controls on a page, modify the default Microsoft Outlook item events, and even create automated procedures, such as mailing a notice to all the contacts in a Contacts folder.

You add VBScript code to an Outlook form to respond to Click events that are fired by controls on the form, or to respond to events fired by the items that have the same message class as the form. VBScript makes it especially easy to respond to item events because the VBScript code executes in the context of the item, so you don’t have to set an object variable to point to the item. In addition, VBScript code is compact and can be contained within a form sent to other users.

With VBScript, you have full access to the Microsoft Outlook object model, except for two areas: VBScript code cannot respond to events other than item and form events, and you cannot use named constants defined in the Outlook object type library.

You can also use Visual Basic for Applications in Outlook to respond to Outlook events and to create macros that automate procedures. Unlike VBScript code, however, Visual Basic for Applications code cannot be contained in a form and so cannot accompany an item that is sent to other users.

For more information about using VBScript, see Create custom forms by using VBScript.


How can I prevent the VBScript code from running?

To prevent any VBScript code from running, hold down the SHIFT key. For example, hold down SHIFT while you open an item to prevent the VBScript code for the Open event from running.


Variants supported in VBScript

Microsoft VBScript in Outlook uses only the Variant data type.

A Variant is a special kind of data type that can contain different kinds of information, depending on how it's used. Because Variant is the only data type in VBScript, it's also the data type returned by all functions in VBScript.

At its simplest, a Variant can contain either numeric or string information. A Variant behaves as a number when you use it in a numeric context and as a string when you use it in a string context. That is, if you're working with data that looks like numbers, VBScript assumes that it is numbers and does the thing that is most appropriate for numbers. Similarly, if you're working with data that can only be string data, VBScript treats it as string data. Of course, you can always make numbers behave as strings by enclosing them in quotation marks (" ").


Using the Script Editor

The Microsoft Script Editor allows you to add VBScript procedures that respond to events generated by items or form controls.

To open the Script Editor

  1. Open an item of the type to which you want to add code.
  2. On the Tools menu, point to Forms and then click Design This Form.
  3. On the Form menu, click View Code.

The Script Editor makes it easy to insert the template for an item event handler.

To insert a blank item event handler

  1. On the Script menu, click Event Handler.
  2. Select the event you want to respond to, and then click OK.

The Script Editor can move the insertion point to a specific line of code. This makes it easy to debug the script when Microsoft Outlook reports an error at a specific location.

To move to a specific line

  1. On the Edit menu, click Go To.
  2. In the Line Number box, type in the number of the line of code to which you want to go.

Learn about the Script Debugger.

Learn about the Outlook object browser.


About the Outlook object browser

The Microsoft Outlook object browser displays the classes, properties, methods, and events available from the Outlook object library. The object browser lets you view and insert these objects into the Script Editor and obtain information about the syntax for using the object.

Learn about viewing and using the object browser.


About the Outlook script debugger

The Microsoft Script Debugger provides you with a comprehensive debugging environment for testing and correcting errors in the VBScript code that you created for your Microsoft Outlook forms. The Script Debugger is a shared component that can also be used to track down errors in any Microsoft ActiveX-enabled scripting language and to debug Java applets, beans, and ActiveX components.

The Microsoft Script Debugger lets you debug both client scripts and server scripts.

The Microsoft Script Debugger works the way many debuggers do, by allowing you to:

  • View the source code of the script that you are debugging.
  • Control the pace of the script execution.
  • View and change variable and property values.
  • View and control script flow.

The script debugger is only available in Outlook at run time.

Learn about using the Script Debugger in Outlook.


Set global variables for a form

A global variable is available to any procedure in a form while the script is running. To set a global variable, assign the value to the variables before any procedures.


Referencing controls on an Outlook form

If you need to refer to a control on an Outlook form within a procedure, you must also reference the inspector, page, and controls collection that contains the control, even if you are referencing the control with its own event procedure. The following example shows how to change the caption of a command button when it’s clicked. To test this example, in design mode create a command button with the default name CommandButton1 on the page P.2.

Sub CommandButton1_Click
    Set myButton = Item.GetInspector.ModifiedFormPages("P.2")_
       .Controls("CommandButton1")
    myButton.Caption = "New Caption"
End Sub


Common things you can do with VBScript

The following are common things you can do with VBScript in an Outlook Form.

What do you want to do?

Create an Outlook item

Add a Click event for a control

Add an Outlook event

Reference the active user

Change the value of a field

Reference a folder

Use properties from the Microsoft Exchange Server global address list

Put a list of fields and values in the message body


Form Events

Form events occur when something happens to an item displayed in a form, such as when it's saved or opened or when a user-defined action is started.

Most often, form events are handled by VBScript code within the form itself.

Some events can be cancelled. That is, your event handler can prevent Microsoft Outlook from performing the default action associated with the event. For example, you can write an event handler for the Forward event to prevent an item from being sent to recipients who are not on a list of approved recipients. Learn about canceling an event.

The following table lists the form events supported by Outlook.

Event | Cancelable? | Description
AttachmentAdd | No | Occurs when an attachment has been added to the item
AttachmentRead | No | Occurs when an attachment has been opened for reading
BeforeAttachmentSave | Yes | Occurs before an attachment is saved
BeforeCheckNames | Yes | Occurs before Outlook starts resolving names in the recipients collection of the item
Close | Yes | Occurs before Outlook closes the inspector displaying the item
CustomAction | Yes | Occurs before Outlook executes a custom action of an item
CustomPropertyChange | No | Occurs when a custom item property has changed
Forward | Yes | Occurs before Outlook executes the Forward action of an item
Open | Yes | Occurs before Outlook opens an inspector to display the item
PropertyChange | No | Occurs when an item property has changed
Read | No | Occurs when an item is opened for editing by a user
Reply | Yes | Occurs before Outlook executes the Reply action of an item
ReplyAll | Yes | Occurs before Outlook executes the Reply to All action of an item
Send | Yes | Occurs before Outlook sends the item
Write | Yes | Occurs before Outlook saves the item in a folder


Control Events

Outlook form controls support only one event, the Click event.

A control bound to a field does not fire the Click event. You must handle the appropriate field event to detect a user’s interaction with a control bound to a field.

The following controls fire the Click event whenever a user clicks anywhere in the control.

CheckBox

CommandButton

Frame

Image

Label

OptionButton

ToggleButton

The following controls fire the Click event when the user selects an item in the list.

ComboBox

ListBox

The following controls do not support the Click event.

MultiPage

ScrollBar

SpinButton

TabStrip

TextBox

While the MultiPage control itself does not support the Click event, an individual Page on a MultiPage control will fire the Click event if the user clicks inside the client area of the page, but not if the user clicks the tab associated with the page.

To detect a change in a TextBox control, bind the control to a field and then handle the appropriate field event.


Field Events

Microsoft Outlook provides two events to notify your program that a field (property) in an item has changed. The PropertyChange event is fired whenever a standard Outlook field in an item has changed. Outlook fires the CustomPropertyChange event whenever a user-defined field changes.

A control that is bound to a field does not fire the Click event, whether the control was selected from the Control Toolbox and subsequently bound to a field, or was selected from the Field Chooser. Consequently, you must use the PropertyChange or CustomPropertyChange event to detect user interaction with a bound control.


Canceling an event

Microsoft Outlook calls event handlers in your program to allow your program to respond to such events as actions that the user takes or changes in the message store. Each event is accompanied by a default action that Outlook performs as a result of the event. For example, when the Open event occurs for an item, by default Outlook displays the item in an inspector window.

Some events only notify your program that a particular event has occurred. For these events, your event handler simply responds to the event. With other events, Outlook allows your event handler to cancel the event, that is, to instruct Outlook not to perform the default action associated with the event. In the case of the Open event, for example, your program can prevent Outlook from displaying the item in an inspector. If an event can be cancelled, the reference topic describing the event indicates how to cancel the event.

If an event can be cancelled, an event handler written in Microsoft Visual Basic or Microsoft Visual Basic for Applications receives a parameter that it sets before returning to indicate whether the event should be cancelled. For example, an event handler for the Open event written in Visual Basic for Applications might look like this. This example assumes that the value of OpenOK is set elsewhere.

Sub myItem_Open(byRef Cancel as Boolean)
    If OpenOK Then
        Cancel = False ' Outlook performs default action
    Else
        Cancel = True  ' Outlook does not perform default action
    EndIf
End Sub

Because of limitations in VBScript, however, this syntax cannot be used. An event handler for the Open event in the script of an item must be written as a function. To cancel the event, the value of the function is set to False before returning, as in the following example.

Function Item_Open()
    If OpenOK Then
        Item_Open = True  ' Outlook performs default action
    Else
        Item_Open = False ' Outlook does not perform default action
    End If
End Function


About the order of events

The following events occur in the order specified when a user completes an action.

Events | When
Open | A form is opened to compose an item.
Send, Write, Close | An item is sent.
Write, Close | An item is posted.
Write | An item is saved.
Close | An item is closed.
Read, Open | An item is opened in a folder.
Reply | A user replies to an item's sender.
ReplyAll | A user replies to an item's sender and all recipients.
Forward | The newly-created item is passed to the procedure after the user selects the Forward action for an item.
PropertyChange | One of the item's standard properties is changed.
CustomPropertyChange | One of the item's custom properties is changed.
CustomAction | A user-defined action is initiated.

The Click event occurs only when you have defined it for a control in the Script Editor.


Test tips for using VBScript in Outlook

There are several ways to test code in Outlook. If there is a syntax error in the code, when you run the form, an error message appears with the line number of the code. You can then go to the specific line of code. You can also use the Script Debugger and other methods to isolate run-time errors.

What do you want to do?

Go to a line of code

Use the Script Debugger

Use message boxes to return values

Set global variables for a form

Use the PropertyChange event to test procedures


About the object environment

There are two ways to write code for Outlook:

  • From outside the application, such as by using Microsoft Visual Basic or Microsoft Visual Basic for Applications in Microsoft Excel or another application.
  • From inside the application, such as by using Visual Basic for Applications or by using VBScript with an Outlook form.

Learn more about the differences between using Visual Basic for Applications and VBScript

The major components of the Outlook object model are:

Application The top of the object hierarchy that represents the entire application. Enables you to reference other objects in the application and create items and objects. For example, this code creates an appointment in Outlook Visual Basic for Applications or VBScript:
Application.CreateItem(1).Display
NameSpace Represents the MAPI message store where all the Outlook items are stored. Provides methods for logging on and off Outlook and for referencing the default folders such as Mailbox, Inbox, Contacts, and others. For example, this code references the active user in Outlook Visual Basic for Applications or VBScript:
Application.GetNameSpace("MAPI").CurrentUser
Explorer Represents the Outlook window. Enables you to show, return, and close the active window. For example, this code shows the active Outlook window in Outlook Visual Basic for Applications or VBScript:
Application.ActiveExplorer.Display
Folders There are two folder objects, the Folders collection object that enables you to work with collections of folders and the MAPIFolder object that enables you to work with a single folder. For example, this code shows the collection of folders named Personal Folders in Outlook Visual Basic for Applications or VBScript:
Application.GetNameSpace("MAPI").Folders("Personal Folders")
Outlook items There are two item objects, the Items collection object that enables you to work with items within a folder and the item objects that represents the standard item types in Outlook, such as MailItem that represents a mail message. In VBScript, the active item is assumed, so you do not need to enter the object model to reference it. For example, this code sets the Subject field of the active message in VBScript:
Item.Subject = "New Subject"
Inspector References forms. Use to show forms and pages. For example, this code shows the Options page of a form in Outlook Visual Basic for Applications or VBScript:
Application.ActiveInspector.SetCurrentFormPage("Options")
AddressEntry | Each AddressEntry object in the AddressEntries collection holds information that represents a person or process to which the messaging system can deliver messages.
AddressList | The AddressList object is an address book that contains a set of AddressEntry objects. The entire hierarchy is available through the parent AddressLists collection.
Exception | The Exception object holds information about one instance of an AppointmentItem object which is an exception to a recurring series. Unlike most of the other Outlook objects, the Exception object is a read-only object.
Control There are two control objects, the Controls collection object that enables you to work with all the controls on a page and the specific control object that enables you to work with a control. For example, this code sets the Caption of a CommandButton control named "CommandButton1" on a page named "Test" in VBScript:
Item.GetInspector.ModifiedFormPages("Test").Controls("CommandButton1").Caption = "New Caption"


Constants and variables in VBScript

In VBScript, constants must be referenced by their numeric values. The constant string does not work and returns a value of 0, which gives unpredictable results.

There are two types of variables. Procedure-level variables that are used only within a procedure and script-level variables that are available to all the procedures within your script. Declare script-level variables at the top of your script. Declare procedure-level variables inside procedures. You can use procedure-level variables with the same name in different procedures because each variable is recognized only by the procedure in which it's declared. When the procedure exits, the variable ends. Variables that refer to Outlook objects can be either procedure-level or script-level variables. However, the value of the variable must be set within a procedure. Do not attempt to access Outlook objects outside of a procedure.

Rules about variables:

  • Must begin with an alphanumeric character.
  • Cannot contain an embedded period.
  • Cannot exceed 255 characters.
  • Cannot use more than 127 procedure-level variables (arrays count as a single variable).
  • Cannot use more than 127 script-level variables.


Referencing fields

When you need to access the fields in an item, the method you use depends on whether the field is a standard, built-in Microsoft Outlook field, or a custom field.

In either case, you do not access the field directly. Instead, you refer to the field as a property of the item you’ re working with.

For example, to retrieve the text from the Subject field of a mail message, you use the Subject property of the item, as shown in the following VBScript example.

mySubject = Item.Subject

If the field is a custom (user-defined) field, you access it using the UserProperties property of the item, as shown in the following VBScript example. This example assumes that the item already contains a custom field named ReferredBy.

MyReferral = Item.UserProperties("ReferredBy")


Reference a folder

To reference a folder by the name of the folder, use the following code.

Application.GetNameSpace("MAPI").Folders("Personal Folders").Folders("Product Ideas")

To reference a folder by a number, use the following code. In this example, the first folder in the folder collection Personal Folders is referenced.

Application.GetNameSpace("MAPI").Folders("Personal Folders").Folders(1)

To reference any of the default Outlook folders, use the GetDefaultFolder method. Use the value from the table below to specify the folder you want to create.

Application.GetNameSpace("MAPI").GetDefaultFolder(6)
Default folder | Has the value
Deleted Items | 3
Outbox | 4
Sent Items | 5
Inbox | 6
Calendar | 9
Contacts | 10
Journal | 11
Notes | 12
Tasks | 13


Creating a new item

To create a new item, use the CreateItem method of the Application object. This method returns an object that you can then use to work with the item.

The following Microsoft Visual Basic for Applications example shows how to create a mail message, add text to its subject and body, and display it. To use this sample, create a command button named Command1 on a form.

Private Sub Command1_Click()
    Dim myOLApp As New Outlook.Application
    Dim myOLItem As Outlook.MailItem
    Set myOLItem = myOLApp.CreateItem(olMailItem)
    With myOLItem
        .Subject = "Sample item"
        .Body = "This is a sample message."
    End With
    myOLItem.Display
End Sub

The following example shows how to perform the same task using VBScript in a form.

Sub CommandButton1_Click()
    Set myOLItem = Application.CreateItem(0)
    myOLItem.Subject = "Sample item"
    myOLItem.Body = "This is a sample message."
    myOLItem.Display
End Sub


Referencing existing items in a folder

There are a number of ways you can reference existing items in a folder using Microsoft Visual Basic. This topic provides information about:

  • Using a For … Next or For Each … Next loop
  • Using the Items collection
  • Using the Find method
  • Using the Restrict method

Using a For…Next or For Each...Next Loop

Typically these statements are used to loop through all of the items in a folder. The Items collection contains all the items in a particular folder, and you can specify which item to reference by using an index with the Items collection. This is typically used with the For I = 1 to n programming construct.

You can use For Each...Next to loop through the items in the collection without specifying an index. Both approaches achieve the same result.

The following examples use For…Next to loop through all the contacts in the Contacts folder and display the Full Name field in a dialog box.

' Visual Basic/Visual Basic for Applications code example.
Set ol = New Outlook.Application
Set olns = ol.GetNameSpace("MAPI")
' Set MyFolder to the default contacts folder.
Set MyFolder = olns.GetDefaultFolder(olFolderContacts)
' Get the number of items in the folder.
NumItems = MyFolder.Items.Count
' Set MyItem to the collection of items in the folder.
Set myItems = myFolder.Items.Restrict("[MessageClass] = 'IPM.Contact'")
' Loop through all of the items in the folder.
For I = 1 to NumItems
   MsgBox MyItems(I).FullName
Next

' VBScript code example.
Set olns = Item.Application.GetNameSpace("MAPI")
' Set MyFolder to the default contacts folder.
Set MyFolder = olns.GetDefaultFolder(10)
' Get the number of items in the folder.
NumItems = MyFolder.Items.Count
' Set MyItem to the collection of items in the folder.
Set myItems = myFolder.Items.Restrict("[MessageClass] = 'IPM.Contact'")
' Loop through all of the items in the folder.
For I = 1 to NumItems
   MsgBox MyItems(I).FullName
Next

The following examples use For Each...Next to achieve the same result as the preceding examples:

' Visual Basic/Visual Basic for Applications code example.
Set ol = New Outlook.Application
Set olns = ol.GetNameSpace("MAPI")
' Set MyFolder to the default contacts folder.
Set MyFolder = olns.GetDefaultFolder(olFolderContacts)
' Set MyItems to the collection of items in the folder.
Set myItems = myFolder.Items.Restrict("[MessageClass] = 'IPM.Contact'")
For Each SpecificItem in MyItems
   MsgBox SpecificItem.FullName
Next
' VBScript code example.
Set olns = Item.Application.GetNameSpace("MAPI")
' Set MyFolder to the default contacts folder.
Set MyFolder = olns.GetDefaultFolder(10)
' Set MyItem to the collection of items in the folder.
Set myItems = myFolder.Items.Restrict("[MessageClass] = 'IPM.Contact'")
For Each SpecificItem in MyItems
   MsgBox SpecificItem.FullName
Next

Using the Items Collection

You can also use the Items collection and specify a text string that matches the Subject field of an item. The following examples display an item in the Inbox whose subject contains "Please help on Friday!"

' Visual Basic/Visual Basic for Applications code example.
Set ol = New Outlook.Application
Set olns = ol.GetNameSpace("MAPI")
' Set MyFolder to the default Inbox.
Set MyFolder = olns.GetDefaultFolder(olFolderInbox)
Set MyItem = MyFolder.Items("Please help on Friday!")
MyItem.Display

' VBScript code example.
Set olns = Item.Application.GetNameSpace("MAPI")
' Set MyFolder to the default Inbox.
Set MyFolder = olns.GetDefaultFolder(6)
Set MyItem = MyFolder.Items("Please help on Friday!")
MyItem.Display

Using the Find Method

Use the Find method to search for an item in a folder based on the value of one of its fields. If the search is successful, you can then use the FindNext method to check for additional items that meet the same search criteria.

The following examples search to see if you have any high priority tasks.

' Visual Basic/Visual Basic for Applications code example.
Set ol = New Outlook.Application
Set olns = ol.GetNamespace("MAPI")
Set myFolder = olns.GetDefaultFolder(olFolderTasks)
Set MyTasks = myFolder.Items
' Importance corresponds to Priority on the task form.
Set MyTask = MyTasks.Find("[Importance] = ""High""")
If MyTask Is Nothing Then ' the Find failed
   MsgBox "Nothing important. Go party!"
Else
   MsgBox "You have something important to do!"
End If

' VBScript code example.
Set olns = Item.Application.GetNamespace("MAPI")
Set myFolder = olns.GetDefaultFolder(13)
Set MyTasks = myFolder.Items
' Importance corresponds to Priority on the task form.
Set MyTask = MyTasks.Find("[Importance] = ""High""")
If MyTask Is Nothing Then ' the Find failed
   MsgBox "Nothing important. Go party!"
Else
   MsgBox "You have something important to do!"
End If

Using the Restrict Method

The Restrict method is similar to the Find method, but instead of returning a single item, it returns a collection of items that meet the search criteria. For example, you could use this method to find all contacts that work at the same company.

The following examples display all of the contacts that work atProseWare Corporation:

' Automation code example.
Set ol = New Outlook.Application
Set olns = ol.GetNameSpace("MAPI")
Set MyFolder = olns.GetDefaultFolder(olFolderContacts)
Set myItems = myFolder.Items.Restrict("[MessageClass] = 'IPM.Contact'")
MyClause = "[CompanyName] = ""ProseWare"""
Set MyPWItems = MyItems.Restrict(MyClause)
For Each MyItem in MyPWItems
   MyItem.Display
Next

' VBScript code example.
Set olns = Item.Application.GetNameSpace("MAPI")
Set MyFolder = olns.GetDefaultFolder(10)
Set myItems = myFolder.Items.Restrict("[MessageClass] = 'IPM.Contact'")
MyClause = "[CompanyName] = ""ProseWare"""
Set MyPWItems = MyItems.Restrict(MyClause)
For Each MyItem in MyPWItems
   MyItem.Display
Next


Filtering items in a collection

You can use the Microsoft Outlook object model to return information about all items in a folder. Often, however, the desired objective is to search for a specific item or to retrieve a subset of the items in the folder. Consider the following examples:

  • You are developing a Microsoft Access database. When the user enters a new contact record, you want to give the user the ability to click a button to check whether a contact with the same name already exists in Outlook. If a match is found, you can retrieve all the fields for the contact and automatically fill in the Access database record. In this situation, if the user filled in the first and last name fields on the Access form, you can use the Find method in the Outlook object model to search for a match against the Outlook Full Name field. If you want to make sure there are no additional contacts in Outlook with the same name, you can then use the FindNext method to conduct the same search again.
  • You are writing a Microsoft Visual Basic program to automatically schedule appointments in users’ calendars. In order to do this, you need to retrieve a user’s appointments for a given day. In this case, you would use the Restrict method to retrieve all appointments that fall on a particular day.

While the Find and Restrict methods perform different functions, the syntax for both is similar. Following are some tips for using these methods:

  • The filters used with Find and Restrict are not case-sensitive.
  • It is not possible to use these methods if you need to search for a string that’s contained within an Outlook field, commonly called a "Contains" operation. If you need to perform a Contains operation, you can iterate through all of the items in the folder and use the Visual Basic InStr function to see if your search string is contained within an Outlook field.
  • To create a filter that performs a "begins with" operation, use the >, < , >=, and <= operators. For example, to search for all contacts whose last names begin with "Mc", use this filter: ""[LastName] >= ""Mc"" and [LastName] < ""Md"""
  • You can use the contents of a variable as part of the filter.


Working with command bars

In Microsoft Outlook 2000, toolbars, menu bars, and shortcut menus are all controlled programmatically as one type of object: command bars. All the following items are represented in Microsoft Visual Basic by CommandBar objects:

  • Menu bars, toolbars, and shortcut menus
  • Menus on menu bars and toolbars
  • Submenus on menus, submenus, and shortcut menus

You can modify any built-in menu bar or toolbar, and you can create and modify custom toolbars, menu bars, and shortcut menus to deliver with your Visual Basic application. You can present the features of your application as buttons on toolbars or as groups of command names on menus. Because toolbars and menus are both command bars, you use the same kind of controls on both of them. Menu bars and toolbars can both contain menus.

In Visual Basic, buttons and menu items are represented by CommandBarButton objects. The pop-up controls that display menus and submenus are represented by CommandBarPopup objects.

You can also add text boxes, drop-down list boxes, and combo boxes to any command bar. These three types of controls are all represented in Visual Basic by CommandBarComboBox objects.

Note Although they share similar appearances and behaviors, command bar controls and ActiveX controls are not the same. You cannot add ActiveX controls to command bars, and you cannot add command bar controls to documents or forms.

The built-in command bar controls in Outlook are also represented by CommandBarButton, CommandBarPopup, and CommandBarComboBox objects, but their appearances and behaviors may be different from those you can add yourself. You can modify the location and appearance of built-in controls, you cannot modify their built-in behavior.


CheckBox control

Displays the selection state of an item.

Remarks

Use a CheckBox to give the user a choice between two values such as Yes/No, True/False, or On/Off. When the user selects a CheckBox, it displays a special mark (such as an X) and its current setting is Yes, True, or On. If the user does not select the CheckBox, it is empty and its setting is No, False, or Off. Depending on the value of the TripleState property, a CheckBox can also have a null value.

If a CheckBox is bound to a data source, changing the setting changes the value of that source. A disabled CheckBox shows the current value, but is dimmed and does not allow changes to the value from the user interface.

You can also use check boxes inside a group box to select one or more of a group of related items. For example, you can create an order form that contains a list of available items, with a CheckBox preceding each item. The user can select a particular item or items by checking the corresponding CheckBox.

The default property of a CheckBox is the Value property.

Note The ListBox also lets you put a check mark by selected options. Depending on your application, you can use the ListBox instead of using a group of CheckBox controls.


ComboBox control

Combines the features of a ListBox and a TextBox. The user can enter a new value, as with a TextBox, or the user can select an existing value as with a ListBox.

Remarks

If a ComboBox is bound to a data source, the ComboBox inserts the value entered or selected by the user into that data source. If a multicolumn combo box is bound, then the BoundColumn property determines which value is stored in the bound data source.

The list in a ComboBox consists of rows of data. Each row can have one or more columns, which can appear with or without headings. Some applications do not support column headings, others provide only limited support.

The default property of a ComboBox is the Value property.

Note If you want more than a single line of the list to appear at all times, you might want to use a ListBox instead of a ComboBox. If you want to use a ComboBox and limit values to those in the list, you can set the Style property of the ComboBox so the control looks like a drop-down list box.


CommandButton control

Starts, ends, or interrupts an action or series of actions.

Remarks

Requires VBScript.

Syntax

Sub CommandButton_Click( )

'write event code here

End Sub

The macro or event procedure assigned to the CommandButton's Click event determines what the CommandButton does. For example, you can create a CommandButton that opens another form. You can also display text, a picture, or both on a CommandButton.

The default property of a CommandButton is the Value property.

The only event for a CommandButton is the Click event.


Font Object

Defines the characteristics of the text used by a control.

Each control has its own Font object to let you set its text characteristics independently of the characteristics defined for other controls. Use font properties to specify the font name, to set bold, italic, or underlined text, or to adjust the size of the text.

The default property for the Font object is the Name property.


Frame control

Creates a functional and visual control group.

Remarks

All option buttons in a Frame are mutually exclusive, so you can use the Frame to create an option group. You can also use a Frame to group controls with closely related contents.For example, in an application that processes customer orders, you might use a Frame to group the name, address, and account number of customers.

You can also use a Frame to create a group of ToggleButtons, but the toggle buttons are not mutually exclusive.

To create a group of mutually exclusive OptionButton controls, you can put the buttons in a Frameon your form, or you can use the GroupName property.


Image control

Displays a picture on a form.

Remarks

The Image control lets you display a picture as part of the data in a form. For example, you might use an Image to display employee photographs in a personnel form.

The Image lets you crop, size, or zoom a picture, but does not allow you to edit the contents of the picture. For example, you cannot use the Image to change the colors in the picture, to make the picture transparent, or to refine the image of the picture. You must use image editing software for these purposes.

The Image supports the following file formats:

  • *.bmp
  • *.cur
  • *.gif
  • *.ico
  • *.jpg
  • *.wmf

Note You can also display a picture on a Label. However, a Label does not let you crop, size, or zoom the picture.<P>


Label control

Displays descriptive text.

Remarks

A Label control on a form displays descriptive text such as titles, captions, pictures, or brief instructions. For example, labels for an address book might include a Label for a name, street, or city.

The default property for a Label is the Caption property.

Note You can also display a picture on a Label. However, a Label does not let you crop, size, or zoom the picture.


ListBox control

Displays a list of values and lets you select one or more.

Remarks

If the ListBox is bound to a data source, the ListBox stores the selected value in that data source.

The ListBox can either appear as a list or as a group of OptionButton controls or CheckBox controls.

The default property for a ListBox is the Value property.

The default event for a ListBox is the Click event.

Note You can't drop text into a drop-down ListBox.

ListBox styles

You can choose between two presentation styles for a ListBox. Each style provides different ways for users to select items in the list.

If the style is Plain, each item is on a separate row; the user selects an item by highlighting one or more rows.

If the style is Option, an OptionButton or CheckBox appears at the beginning of each row. With this style, the user selects an item by clicking the option button or check box. Check boxes appear only when the MultiSelect property is True.


MultiPage control

Presents multiple screens of information as a single set.

Remarks

A MultiPage is useful when you work with a large amount of information that can be sorted into several categories. For example, use a MultiPage to display information from an employment application. One page might contain personal information such as name and address; another page might list previous employers; a third page might list references. The MultiPage lets you visually combine related information, while keeping the entire record readily accessible.

New pages are added to the right of the currently selected page rather than adjacent to it.

A MultiPage is a control that contains a collection of one or more pages.

Each Page of a MultiPage is a form that contains its own controls, and as such, can have a unique layout. Typically, the pages in a MultiPage have tabs so the user can select the individual pages.

By default, a MultiPage includes two pages, called Page1 and Page2. Each of these is a Page object, and together they represent the Pages collection of the MultiPage. If you add more pages, they become part of the same Pages collection.

The default property for a MultiPage is the Value property, which returns the index of the currently active Page in the Pages collection of the MultiPage.

Note The MultiPage control does not support the Click event.


OptionButton control

Shows the selection status of one item in a group of choices.

Remarks

Use an OptionButton to show whether a single item in a group is selected. Note that each OptionButton in a Frame is mutually exclusive.

If an OptionButton is bound to a data source, the OptionButton can show the value of that data source as either Yes/No, True/False, or On/Off. If the user selects the OptionButton, the current setting is Yes, True, or On. If the user does not select the OptionButton, the setting is No, False, or Off. For example, an OptionButton in an inventory-tracking application might show whether an item is discontinued. If the OptionButton is bound to a data source, then changing the setting changes the value of that data source. A disabled OptionButton is dimmed and does not show a value.

Depending on the value of the TripleState property, an OptionButton can also have a null value.

You can also use an OptionButton inside a group box to select one or more of a group of related items. For example, you can create an order form with a list of available items, with an OptionButton preceding each item. The user can select a particular item by checking the corresponding OptionButton.

The default property for an OptionButton is the Value property.


Page Object

One page of a MultiPage or a single member of a Pages collection.

Remarks

Each Page object contains its own set of controls and does not necessarily rely on other pages in the collection for information. A Page inherits some properties from its container; the value of each inherited property is set by the container.

You can reference a Page by its index value. The index value reflects the ordinal position of the Page within the collection. The index of the first Page in a collection is 0; the index of the second Page is 1; and so on.

The default name for the first Page is Page1. The default name for the second Page is Page2.


ScrollBar control

Returns or sets the value of another control based on the position of the scroll box.

Remarks

Requires VBScript.

A ScrollBar is a stand-alone control you can place on a form. It is visually like the scroll bar you see in certain objects such as a ListBox or the drop-down portion of a ComboBox. However, unlike the scroll bars in these controls, the stand-alone ScrollBar is not an integral part of any other control.

To use the ScrollBar to set or read the value of another control, you must write code that uses the ScrollBar's Value property. For example, to use the ScrollBar to update the value of a TextBox, you can write code that reads the Value property of the ScrollBar and then sets the Value property of the TextBox.

The default property for a ScrollBar is the Value property.

Note To create a horizontal or vertical ScrollBar, drag the sizing handles of the ScrollBar horizontally or vertically on the form.


SpinButton control

Increments and decrements numbers.

Remarks

Requires VBScript.

Clicking a SpinButton changes only the value of the SpinButton. You can write code that uses the SpinButton to update the displayed value of another control. For example, you can use a SpinButton to change the month, the day, or the year shown on a date. You can also use a SpinButton to scroll through a range of values or a list of items, or to change the value displayed in a text box.

To display a value updated by a SpinButton, you must assign the value of the SpinButton to the displayed portion of a control, such as the Caption property of a Label or the Text property of a TextBox. To create a horizontal or vertical SpinButton, drag the sizing handles of the SpinButton horizontally or vertically on the form.

The default property for a SpinButton is the Value property.


Tab Object

A Tab is an individual member of a Tabs collection.

Remarks

Visually, a Tab object appears as a rectangle protruding from a larger rectangular area, or as a button adjacent to a rectangular area.

In contrast to a Page, a Tab does not contain any controls. Controls that appear within the region bounded by a TabStrip are contained on the form, as is the TabStrip.

You can reference a Tab by its index value. The index value reflects the ordinal position of the Tab within the collection. The index of the first Tab in a collection is 0; the index of the second Tab is 1; and so on.


TabStrip control

Presents a set of related controls as a visual group.

Remarks

You can use a TabStrip to view different sets of information for related controls.

A TabStrip is a control that contains a collection of one or more tabs.

Each Tab of a TabStrip is a separate object that users can select. Visually, a TabStrip also includes a client area that all the tabs in the TabStrip share.

By default, a TabStrip includes two pages, called Tab1 and Tab2. Each of these is a Tab object, and together they represent the Tabs collection of the TabStrip. If you add more pages, they become part of the same Tabs collection.

For example, the controls might represent information about a daily schedule for a group of individuals, with each set of information corresponding to a different individual in the group. Set the title of each tab to show one individual's name. Then, you can write code that, after you click a tab, updates the controls to show information about the person identified on the tab.

Note The TabStrip is implemented as a container of a Tabs collection, which in turn contains a group of Tab objects. The TabStrip control does not support the Click event.

The default property for a TabStrip is the SelectedItem property.


TextBox control

Displays information from a user or from an organized set of data.

Remarks

A TextBox is the control most commonly used to display information entered by a user. Also, it can display a set of data, such as a table, query, worksheet, or a calculation result. If a TextBox is bound to a data source, then changing the contents of the TextBox also changes the value of the bound data source.

Formatting applied to any piece of text in a TextBox will affect all text in the control. For example, if you change the font or point size of any character in the control, the change will affect all characters in the control.

The default property for a TextBox is the Value property.

Tips on using text boxes

The TextBox is a flexible control governed by the following properties: Text, MultiLine, WordWrap, and AutoSize.

Text contains the text that's displayed in the text box.

MultiLine controls whether the TextBox can display text as a single line or as multiple lines. Newline characters identify where one line ends and another begins. If MultiLine is False (the default value), the text is truncated instead of wrapped.

WordWrap allows the TextBox to wrap lines of text that are longer than the width of the TextBox into shorter lines that fit. The default value is True.

If you do not use WordWrap, the TextBox starts a new line of text when it encounters a newline character in the text. If WordWrap is turned off, you can have text lines that do not fit completely in the TextBox. The TextBox displays the portions of text that fit inside its width and truncates the portions of text that do not fit. WordWrap is not applicable unless MultiLine is True.

AutoSize controls whether the TextBox adjusts to display all of the text. When using AutoSize with a TextBox, the width of the TextBox shrinks or expands according to the amount of text in the TextBox and the font size used to display the text. The default value is False.

AutoSize works well in the following situations:

  • Displaying a caption of one or more lines.
  • Displaying the contents of a single-line TextBox.
  • Displaying the contents of a multiline TextBox that is read-only to the user.

Note Avoid using AutoSize with an empty TextBox that also uses the MultiLine and WordWrap properties. When the user enters text into a TextBox with these properties, the TextBox automatically sizes to a long narrow box one character wide and as long as the line of text.


ToggleButton control

Shows the selection state of an item.

Remarks

Use a ToggleButton to show whether an item is selected. If a ToggleButton is bound to a data source, the ToggleButton shows the current value of that data source as either Yes/No, True/False, On/Off, or some other choice of two settings. If the user selects the ToggleButton, the current setting is Yes, True, or On. If the user does not select the ToggleButton, the setting is No, False, or Off. If the ToggleButton is bound to a data source, changing the setting changes the value of that data source. A disabled ToggleButton shows a value, but is dimmed and does not allow changes from the user interface.

You can also use a ToggleButton inside a Frame to select one or more of a group of related items. For example, you can create an order form with a list of available items, with a ToggleButton preceding each item. The user can select a particular item by selecting the appropriate ToggleButton.

The default property of a ToggleButton is the Value property.

The only event for a ToggleButton is the Click event.


Click Event

The Click event occurs only if it has been defined for a control in the Script Editor.

The TabStrip and MultiPage controls do not support the Click event. However, individual the Page objects of the MultiPage control do support the click event.

ScrollBars and SpinButtons do not support the Click event but you can bind them to fields and use the CustomPropertyChange event.

The Click event occurs in one of two cases:

  • The user clicks a control with the mouse.
  • The user definitively selects a value for a control with more than one possible value.

Syntax

Sub object_Click( )

The Click event syntax has these parts:

Part | Description
object | Required. A valid object.

Example:

Sub CommandButton1_Click()
    MsgBox "You just clicked my button! "
End Sub

Remarks

Of the two cases where the Click event occurs, the first case applies to the CommandButton, Frame, Image, Label, and Page.

The second case applies to the CheckBox, ComboBox, ListBox, and ToggleButton. It also applies to an OptionButton when the value changes to True.

The following are examples of actions that initiate the Click event:

  • Clicking a blank area of a form or a disabled control (other than a list box) on the form.
  • Clicking a CommandButton.
  • Pressing the SPACEBAR when a CommandButton has the focus.
  • Clicking a control with the left mouse button (left-clicking).
  • Pressing ENTER on a form that has a command button whose Default property is set to True, as long as no other command button has the focus.
  • Pressing ESC on a form that has a command button whose Cancel property is set to True, as long as no other command button has the focus.
  • Pressing a control's accelerator key.

For some controls, the Click event occurs when the Value property changes. However, using the PropertyChange or CustomPropertyChange event is the preferred technique for detecting a new value for a property. The following are examples of actions that initiate the Click event due to assigning a new value to a control:

  • Clicking a CheckBox or ToggleButton, pressing the SPACEBAR when one of these controls has the focus, pressing the accelerator key for one of these controls, or changing the value of the control in code.
  • Changing the value of an OptionButton to True. Setting one OptionButton in a group to True sets all other buttons in the group to False, but the Click event occurs only for the button whose value changes to True.
  • Selecting a value for a ComboBox or ListBox so that it unquestionably matches an item in the control's drop-down list. For example, if a list is not sorted, the first match for characters typed in the edit region may not be the only match in the list, so choosing such a value does not initiate the Click event. In a sorted list, you can use entry-matching to ensure that a selected value is a unique match for text the user types.

The Click event is not initiated when Value is set to Null.

Note Left-clicking changes the value of a control, thus it initiates the Click event. Right-clicking does not change the value of the control, so it does not initiate the Click event.

Also Note If you bind a ListBox, ComboBox, OptionButton, or CheckBox to a field, then the Click event does not fire. You need to use the PropertyChange or CustomPropertyChange event to detect the change via code.

Example:

Sub Item_PropertyChange(ByVal Name)
Set MyListBox = Item.GetInspector.ModifiedFormPages("Message").Controls("ListBox1")
Select Case Name
    Case "Mileage"
        Item.CC = MyListBox.Value
        Item.Subject = MyListBox.Value
    Case Else
End Select
End Sub


Add Method

Adds a control by its programmatic identifier (ProgID) to a page or adds or inserts a Tab or Page in a TabStrip or MultiPage.

Syntax

For MultiPage, TabStrip
Set Object = object.Add( [ Name [, Caption [, index]]])

For other controls
Set Control = object.Add( ProgID [, Name [, Visible]])

The Add method syntax has these parts:

Part | Description
object | Required. A valid object name.
Name | Optional. Specifies the name of the object being added. If a name is not specified, the system generates a default name based on the rules of the application where the form is used.
Caption | Optional. Specifies the caption to appear on a tab or a control. If a caption is not specified, the system generates a default caption based on the rules of the application where the form is used.
index | Optional. Identifies the position of a page or tab within a Pages or Tabs collection. If an index is not specified, the system appends the page or tab to the end of the Pages or Tabs collection and assigns the appropriate index value.
ProgID | Required. Programmatic identifier. A text string with no spaces that identifies an object class. The standard syntax for a ProgID is <Vendor>.<Component>.<Version>. A ProgID is mapped to a class identifier (CLSID).
Visible | Optional. True if the object is visible (default). False if the object is hidden.

Settings

ProgID values for individual controls are:

CheckBox | Forms.CheckBox.1
ComboBox | Forms.ComboBox.1
CommandButton | Forms.CommandButton.1
Frame | Forms.Frame.1
Image | Forms.Image.1
Label | Forms.Label.1
ListBox | Forms.ListBox.1
MultiPage | Forms.MultiPage.1
OptionButton | Forms.OptionButton.1
ScrollBar | Forms.ScrollBar.1
SpinButton | Forms.SpinButton.1
TabStrip | Forms.TabStrip.1
TextBox | Forms.TextBox.1
ToggleButton | Forms.ToggleButton.1

Remarks

For a MultiPage control, the Add method returns a Page object. For a TabStrip, it returns a Tab object. The index value for the first Page or Tab of a collection is 0, the value for the second Page or Tab is 1, and so on.

For the Controls collection of an object, the Add method returns a control corresponding to the specified ProgID. The AddControl event occurs after the control is added.

The following syntax will return the Text property of a control added at design time:

userform1.thebox.text

If you add a control at run time, you must use the exclamation syntax to reference properties of that control. For example, to return the Text property of a control added at run time, use the following syntax:

userform1!thebox.text

Note You can change a control's Name property at run time only if you added that control at run time with the Add method.


AddItem Method

For a single-column ListBox or ComboBox, the AddItem method adds an item to the list. For a multicolumn ListBox or ComboBox, this method adds a row to the list.

Syntax

Variant = object.AddItem( [ item [, varIndex]])

The AddItem method syntax has these parts:

Part | Description
object | Required. A valid object.
Item | Optional. Specifies the item or row to add. The number of the first item or row is 0; the number of the second item or row is 1, and so on.
varIndex | Optional. Integer specifying the position within the object where the new item or row is placed.

Remarks

If you supply a valid value for varIndex, the AddItem method places the item or row at that position within the list. If you omit varIndex, the method adds the item or row at the end of the list.

The value of varIndex must not be greater than the value of the ListCount property.

For a multicolumn ListBox or ComboBox, AddItem inserts an entire row, that is, it inserts an item for each column of the control. To assign values to an item beyond the first column, use the List or Column property and specify the row and column of the item.

If the control is bound to data, the AddItem method fails.

Note You can add more than one row at a time to a ComboBox or ListBox by using List.


Clear Method

Removes all objects from an object or collection.

Syntax

object.Clear

The Clear method syntax has these parts:

Part | Description
object | Required. A valid object.

Remarks

For a MultiPage or TabStrip, the Clear method deletes individual pages or tabs.

For a ListBox or ComboBox, Clear removes all entries in the list.

For a Controls collection, Clear deletes controls that were created at run-time with the Add method. Using Clear on controls created at design-time causes an error.

Note If the control is bound to data, the Clear method fails.


Copy Method

Copies the contents of an object to the Clipboard.

Syntax

object.Copy

The Copy method syntax has these parts:

Part | Description
object | Required. A valid object.

Remarks

The original content remains on the object.

The actual content that is copied depends on the object. For example, on a Page, the Copy method copies the currently selected control or controls. On a TextBox or ComboBox, it copies the currently selected text.

Using Copy for a form, Frame, or Page copies the currently-active control.


Cut Method

Removes selected information from an object and transfers it to the Clipboard.

Syntax

object.Cut

The Cut method syntax has these parts:

Part | Description
object | Required. A valid object.

Remarks

For a ComboBox or TextBox, the Cut method removes currently selected text in the control to the Clipboard. This method does not require that the control have the focus.

On a Page, Frame, or form, Cut removes currently selected controls to the Clipboard. This method only removes controls created at run time.


DropDown Method

Displays the list portion of a ComboBox.

Syntax

object.DropDown

The DropDown method syntax has these parts:

Part | Description
object | Required. A valid object.

Remarks

Use the DropDown method to open the list in a combo box.


GetFormat Method

Returns an integer value indicating whether a specific format is on the DataObject.

Syntax

Boolean = object.GetFormat( format)

The GetFormat method syntax has these parts:

Part | Description
object | Required. A valid object.
format | Required. An integer or string specifying a specific format that might exist in the DataObject. If the specified format exists in the DataObject, GetFormat returns True.

Settings

The settings for format are:

Value | Description
1 | Text format.
A string or any integer other than 1 | A user-defined DataObject format passed to the DataObject from SetText.

Remarks

The GetFormat method searches for a format in the current list of formats on the DataObject. If the format is on the DataObject, GetFormat returns True; if not, GetFormat returns False.

The DataObject currently supports only text formats.


GetFromClipboard Method

Copies data from the Clipboard to a DataObject.

Syntax

String = object.GetFromClipboard( )

The GetFromClipboard method syntax has these parts:

Part | Description
object | Required. A valid object name.

Remarks

The DataObject can contain multiple data items, but each item must be in a different format. For example, the DataObject might include one text item and one item in a custom format; but cannot include two text items.


GetText Method

Retrieves a text string from the DataObject using the specified format.

Syntax

String = object.GetText( [ format])

The GetText method syntax has these parts:

Part | Description
object | Required. A valid object name.
format | Optional. A string or integer specifying the format of the data to retrieve from the DataObject.

Settings

The settings for format are:

Value | Description
1 | Text format.
A string or any integer other than 1 | A user-defined DataObject format passed to the DataObject from SetText.

Remarks

The DataObject supports multiple formats, but only supports one data item of each format. For example, the DataObject might include one text item and one item in a custom format; but cannot include two text items.

If no format is specified, the GetText method requests information in the Text format from the DataObject.


Item Method

Returns a member of a collection, either by position or by name.

Syntax

Set Object = object.Item( collectionindex)

The Item method syntax has these parts:

Part | Description
object | Required. A valid object.
collectionindex | Required. A member's position, or index, within a collection.

Settings

The collectionindex can be either a string or an integer. If it is a string, it must be a valid member name. If it is an integer, the minimum value is 0 and the maximum value is one less than the number of items in the collection.

Remarks

If an invalid index or name is specified, an error occurs.


Move Method

Moves a form or control, or moves all the controls in the Controls collection..

Syntax

For a form or control
object.Move( [Left [, Top [, Width [, Height [, Layout]]]]])

For the Controls collection
object.Move( X, Y)

The Move method syntax has these parts:

Part | Description
object | Required. A valid object name.
Left | Optional. Single-precision value, in points, indicating the horizontal coordinate for the left edge of the object.
Top | Optional. Single-precision value, in points, that specifies the vertical coordinate for the top edge of the object.
Width | Optional. Single-precision value, in points, indicating the width of the object.
Height | Optional. Single-precision value, in points, indicating the height of the object.
Layout | Optional. A Boolean value indicating whether the Layout event is initiated for the control's parent following this move. False is the default value.
X, Y | Required. Single-precision value, in points, that specifies the change from the current horizontal and vertical position for each control in the Controls collection.

Settings

The maximum and minimum values for the Left, Top, Width, Height, X, and Y arguments vary from one application to another.

Remarks

For a form or control, you can move a selection to a specific location relative to the edges of the form that contains the selection.

You can use named arguments, or you can enter the arguments by position. If you use named arguments, you can list the arguments in any order. If not, you must enter the arguments in the order shown, using commas to indicate the relative position of arguments you do not specify. Any unspecified arguments remain unchanged.

For the Controls collection, you can move all the controls in this collection a specific distance from their current positions on a Frame or Page.


Paste Method

Transfers the contents of the Clipboard to an object.

Syntax

object.Paste

The Paste method syntax has these parts:

Part | Description
object | Required. A valid object.

Remarks

Data pasted into a ComboBox or TextBox is treated as text.


PutInClipboard Method

Moves data from a DataObject to the Clipboard.

Syntax

object.PutInClipboard

The PutInClipboard method syntax has these parts:

Part | Description
object | Required. A valid object.

Remarks

The PutInClipboard method replaces the contents of the Clipboard with the contents of the DataObject that is in Text format.


RedoAction Method

Reverses the effect of the most recent Undo action.

Syntax

Boolean = object.RedoAction

The RedoAction method syntax has these parts:

Part | Description
object | Required. A valid object.

Remarks

Redo reverses the last Undo, which is not necessarily the last action taken. Not all actions can be undone.

RedoAction returns True if it was successful.


Remove Method

Removes a member from a collection; or, removes a control from a Frame, or Page.

Syntax

object.Remove( collectionindex)

The Remove method syntax has these parts:

Part | Description
object | Required. A valid object.
collectionindex | Required. A member's position, or index, within a collection. Numeric as well as string values are acceptable. If the value is a number, the minimum value is zero, and the maximum value is one less than the number of members in the collection. If the value is a string, it must correspond to a valid member name.


RemoveItem Method

Removes a row from the list in a list box or combo box.

Syntax

Boolean = object.RemoveItem( index)

The RemoveItem method syntax has these parts:

Part | Description
object | Required. A valid object.
index | Required. Specifies the row to delete. The number of the first row is 0; the number of the second row is 1, and so on.

This method will not remove a row from the list if the ListBox is data bound (that is, when the RowSource property specifies a data source for the ListBox).


Repaint Method

Updates the display by redrawing the frame or page.

Syntax

Boolean = object.Repaint

The Repaint method syntax has these parts:

Part | Description
object | Required. A valid object.

Remarks

The Repaint method is useful if the contents or appearance of an object changes significantly, and you don't want to wait until the system automatically repaints the area.


Scroll Method

Moves the scroll bar on an object.

Syntax

object.Scroll( [ ActionX [, ActionY]])

The Scroll method syntax has these parts:

Part | Description
object | Required. A valid object name.
ActionX | Optional. Identifies the action to occur in the horizontal direction.
ActionY | Optional. Identifies the action to occur in the vertical direction.

Settings

The settings for ActionX and ActionY are:

Value | Description
0 | Do not scroll in the specified direction.
1 | Move up on a vertical scroll bar or left on a horizontal scroll bar. Movement is equivalent to pressing the up or left arrow key on the keyboard to move the scroll bar.
2 | Move down on a vertical scroll bar or right on a horizontal scroll bar. Movement is equivalent to pressing the right or down arrow key on the keyboard to move the scroll bar.
3 | Move one pageup on a vertical scroll bar or one page left on a horizontal scroll bar. Movement is equivalent to pressing PAGE UP on the keyboard to move the scroll bar.
4 | Move one pagedown on a vertical scroll bar or one page right on a horizontal scroll bar. Movement is equivalent to pressing PAGE DOWN on the keyboard to move the scroll bar.
5 | Move to the top of a vertical scroll bar or to the left end of a horizontal scroll bar.
6 | Move to the bottom of a vertical scroll bar or to the right end of a horizontal scroll bar.

Remarks

The Scroll method applies scroll bars that appear on a form, Frame, or Page that is larger than its display area. This method does not apply to the stand-alone ScrollBar or to scroll bars that appear on a TextBox.


SetDefaultTabOrder Method

Sets the TabIndex property of each control on a frame or page, using a default top-to-bottom, left-to-right tab order.

Syntax

object.SetDefaultTabOrder

The SetDefaultTabOrder method syntax has these parts:

Part | Description
object | Required. A valid object.


SetFocus Method

Moves the focus to this instance of an object.

Syntax

object.SetFocus

The SetFocus method syntax has these parts:

Part | Description
object | Required. A valid object.

Remarks

If setting the focus fails, the focus reverts to the previous object and an error is generated.

By default, setting the focus to a control does not activate the control's window or place it on top of other controls.

The SetFocus method is valid for an empty Frame as well as a Frame that contains other controls. An empty Frame will take the focus itself, and any subsequent keyboard events apply to the Frame. In a Frame that contains other controls, the focus moves to the first control in the Frame, and subsequent keyboard events apply to the control that has the focus.


SetText Method

Copies a text string to the DataObject using a specified format.

Syntax

object.SetText( StoreData [, format])

The SetText method syntax has these parts:

Part | Description
object | Required. A valid object.
StoreData | Required. Defines the data to store on the DataObject.
format | Optional. An integer or string specifying the format of StoreData. When retrieving data from the DataObject, the format identifies the piece of data to retrieve.

Settings

The settings for format are:

Value | Description
1 | Text format.
A string or integer value other than 1 | A user-defined DataObject format.

Remarks

The DataObject stores data according to its format. When the user supplies a string, the DataObject saves the text under the specified format.

If the DataObject contains data in the same format as new data, the new data replaces the existing data in the DataObject. If the new data is in a new format, the new data and the new format are both added to the DataObject, and the previously existing data is there as well.

If no format is specified, the SetText method assigns the Text format to the text string. If a new format is specified, the DataObject registers the new format with the system.


StartDrag Method

Initiates a drag-and-drop operation for a DataObject.

Syntax

DropEffect=Object.StartDrag([Effect as DropEffect])

The StartDrag method syntax has these parts:

Part | Description
Object | Required. A valid object.
Effect | Optional. Effect of the drop operation on the target control.

Settings

The settings for Effect are:

Value | Description
0 | Does not copy or move the drop source to the drop target.
1 | Copies the drop source to the drop target.
2 | Moves the drop source to the drop target.
3 | Copies or moves the drop source to the drop target.

Remarks

The drag action starts at the current mouse pointer position with the current keyboard state and ends when the user releases the mouse. The effect of the drag-and-drop operation depends on the effect chosen for the drop target.

For example, a control's MouseMove event might include the StartDrag method. When the user clicks the control and moves the mouse, the mouse pointer changes to indicate whether Effect is valid for the drop target.


UndoAction Method

Reverses the most recent action that supports the Undo command.

Syntax

Boolean = object.UndoAction

The UndoAction method syntax has these parts:

Part | Description
object | Required. A valid object.

Remarks

Not all user actions can be undone. If an action cannot be undone, the Undo command is unavailable following the action.

You must apply this method before the form or control is updated. You may want to include this method in a form's PropertyChange event.


ZOrder Method

Places the object at the front or back of the z-order.

Syntax

object.ZOrder( [ zPosition])

The ZOrder method syntax has these parts:

Part | Description
object | Required. A valid object.
zPosition | Optional. A control's position, front or back, in the container's z-order.

Settings

The settings for zPosition are:

Value | Description
0 | Places the control at the front of the z-order. The control appears on top of other controls (default).
1 | Places the control at the back of the z-order. The control appears underneath other controls.

Remarks

The z-order determines how windows and controls are stacked when they are presented to the user. Items at the back of the z-order are overlaid by closer items; items at the front of the z-order appear to be on top of items at the back. When the zPosition argument is omitted, the object is brought to the front.

In design mode, the Bring to Front or Send To Back commands set the z-order. Bring to Front is equivalent to using the ZOrder method and putting the object at the front of the z-order. Send to Back is equivalent to using ZOrder and putting the object at the back of the z-order.

This method does not affect content or sequence of the controls in the Controls collection.

Note You can't Undo or Redo layering commands, such as Send to Back or Bring to Front. For example, if you select an object and click Move Backward on the shortcut menu, you won't be able to Undo or Redo that action.


Accelerator Property

Sets or retrieves the accelerator key for a control.

Syntax

object.Accelerator [= String]

The Accelerator property syntax has these parts:

Part | Description
object | Required. A valid object.
String | Optional. The character to use as the accelerator key.

Remarks

To designate an accelerator key, enter a single character for the Accelerator property. You can set Accelerator in the control's property sheet or in code. If the value of this property contains more than one character, the first character in the string becomes the value of Accelerator.

When an accelerator key is used, there is no visual feedback (other than focus) to indicate that the control initiated the Click event. For example, if the accelerator key applies to a CommandButton, the user will not see the button pressed in the interface. The button receives the focus, however, when the user presses the accelerator key.


ActiveControl Property

Identifies and allows manipulation of the control that has the focus.

Syntax

object.ActiveControl

The ActiveControl property syntax has these parts:

Part | Description
object | Required. A valid object.

Remarks

The ActiveControl property is read-only and is set when you select a control in the interface. You can use ActiveControl as a substitute for the control name when setting properties or calling methods.


Alignment Property

Specifies the position of a control relative to its caption.

Syntax

object.Alignment [= 0,1]

The Alignment property syntax has these parts:

Part | Description
object | Required. A valid object.

Settings

The Settings for Alignment are:

Value | Description
0 | Places the caption to the left of the control.
1 | Places the caption to the right of the control (default).

Remarks

The caption text for a control is left-aligned.


AutoSize Property

Specifies whether an object automatically resizes to display its entire contents.

Syntax

object.AutoSize [= Boolean]

The AutoSize property syntax has these parts:

Part | Description
object | Required. A valid object.
Boolean | Optional. Whether the control is resized.

Settings

The settings for Boolean are:

Value | Description
True | Automatically resizes the control to display its entire contents.
False | Keeps the size of the control constant. Contents are clipped when they exceed the area of the control (default).

Remarks

For controls with captions, the AutoSize property specifies whether the control automatically adjusts to display the entire caption.

For controls without captions, this property specifies whether the control automatically adjusts to display the information stored in the control. In a ComboBox, for example, setting AutoSize to True automatically sets the width of the display area to match the length of the current text.

For a single-line TextBox, setting AutoSize to True automatically sets the width of the display area to the length of the text in the text box.

For a multiline TextBox that contains no text, setting AutoSize to True automatically displays the text as a column. The width of the text column is set to accommodate the widest letter of that font size. The height of the text column is set to display the entire text of the TextBox.

For a multiline TextBox that contains text, setting AutoSize to True automatically enlarges the TextBox vertically to display the entire text. The width of the TextBox does not change.

Note If you manually change the size of a control while AutoSize is True, the manual change overrides the size previously set by AutoSize.


AutoTab Property

Specifies whether an automatic tab occurs when a user enters the maximum allowable number of characters into a TextBox or the text box portion of a ComboBox.

Syntax

object.AutoTab [= Boolean]

The AutoTab property syntax has these parts:

Part | Description
object | Required. A valid object.
Boolean | Optional. Specifies whether an automatic tab occurs.

Settings

The settings for Boolean are:

Value | Description
True | Tab occurs.
False | Tab does not occur (default).

Remarks

The MaxLength property specifies the maximum number of characters allowed in a TextBox or the text box portion of a ComboBox.

You can specify the AutoTab property for a TextBox or ComboBox on a form for which you usually enter a set number of characters. Once a user enters the maximum number of characters, the focus automatically moves to the next control in the tab order. For example, if a TextBox displays inventory stock numbers that are always five characters long, you can use MaxLength to specify the maximum number of characters to enter into the TextBox and AutoTab to automatically tab to the next control after the user enters five characters.


AutoWordSelect Property

Specifies whether the basic unit used to extend a selection is a word or a single character.

Syntax

object.AutoWordSelect [= Boolean]

The AutoWordSelect property syntax has these parts:

Part | Description
object | Required. A valid object.
Boolean | Optional. Specifies the basic unit used to extend a selection.

Settings

The settings for Boolean are:

Value | Description
True | Uses a word as the basic unit (default).
False | Uses a character as the basic unit.

Remarks

The AutoWordSelect property specifies how the selection extends or contracts in the edit region of a TextBox or ComboBox.

If the user places the insertion point in the middle of a word and then extends the selection while AutoWordSelect is True, the selection includes the entire word.


BackColor Property

Specifies the background color of the object.

Syntax

object.BackColor [= Long]

The BackColor property syntax has these parts:

Part | Description
object | Required. A valid object.
Long | Optional. A value or constant that determines the background color of an object.

Settings

You can use any integer that represents a valid color. You can also specify a color by using the RGB function with red, green, and blue color components. The value of each color component is an integer that ranges from zero to 255. For example, you can specify teal blue as the integer value 4966415 or as red, green, and blue color components 15, 200, 75, as shown in the following example.

RGB(15,200,75)

Remarks

You can only see the background color of an object if the BackStyle property is set to 1.


BackStyle Property

Returns or sets the background style for an object.

Syntax

object.BackStyle [=BackStyle]

The BackStyle property syntax has these parts:

Part | Description
object | Required. A valid object.
BackStyle | Optional. Specifies the control background.

Settings

The settings for BackStyle are:

Value | Description
0 | The background is transparent.
1 | The background is opaque (default).

Remarks

The BackStyle property determines whether a control is transparent. If BackStyle is 1, the control is not transparent and you cannot see anything behind the control on a form. If BackStyle is 0, you can see through the control and look at anything on the form located behind the control. The BackColor property is only valid if the BackStyle property is set to 1.

Note BackStyle does not affect the transparency of bitmaps. You must use a picture editor such as Paintbrush to make a bitmap transparent. Not all controls support transparent bitmaps.


Bold, Italic, Size, StrikeThrough, Underline, Weight Properties

Specifies the visual attributes of text on a displayed or printed form.

Syntax

object.Bold [= Boolean]

object.Italic [= Boolean]

object.Size [= Currency]

object.StrikeThrough [= Boolean]

object.Underline [= Boolean]

object.Weight [= Integer]

The Bold, Italic, Size, StrikeThrough, Underline, and Weight property syntaxes have these parts:

Part | Description
object | Required. A valid object name.
Boolean | Optional. Specifies the font style.
Currency | Optional. A number indicating the font size.
Integer | Optional. Specifies the font style.

The settings for Boolean are:

Value | Description
True | The text has the specified attribute (that is bold, italic, size, strikethrough or underline marks, or weight).
False | The text does not have the specified attribute (default).

The Weight property accepts values from 0 to 1000. A value of zero allows the system to pick the most appropriate weight. A value from 1 to 1000 indicates a specific weight, where 1 represents the lightest type and 1000 represents the darkest type.

Remarks

These properties define the visual characteristics of text. The Bold property determines whether text is normal or bold. The Italic property determines whether text is normal or italic. The Size property determines the height, in points, of displayed text. The Underline property determines whether text is underlined. The StrikeThrough property determines whether the text appears with strikethrough marks. The Weight property determines the darkness of the type.

The font's appearance on screen and in print may differ, depending on your computer and printer. If you select a font that your system can't display with the specified attribute or that isn't installed, Windows substitutes a similar font. The substitute font will be as similar as possible to the font originally requested.

Changing the value of Bold also changes the value of Weight. Setting Bold to True sets Weight to 700; setting Bold to False sets Weight to 400. Conversely, setting Weight to anything over 550 sets Bold to True; setting Weight to 550 or less sets Bold to False.

The default point size is determined by the operating system.


BorderColor Property

Specifies the color of an object's border.

Syntax

object.BorderColor [= Long]

The BorderColor property syntax has these parts:

Part | Description
object | Required. A valid object.
Long | Optional. A value that determines the border color of an object.

Settings

You can use any integer that represents a valid color. You can also specify a color by using the RGB function with red, green, and blue color components. The value of each color component is an integer that ranges from zero to 255. For example, you can specify teal blue as the integer value 4966415 or as red, green, and blue color components 15, 200, 75, as shown in the following example.

RGB(15,200,75)

Remarks

To use the BorderColor property, the BorderStyle property must be set to a value other than 0.

BorderStyle uses BorderColor to define the border colors. The SpecialEffect property uses system colors exclusively to define its border colors. For Windows operating systems, system color settings are set using the Display icon in Control Panel. In Windows NT 3.51, system color settings are set using the Color icon in Control Panel.


BorderStyle Property

Specifies the type of border used by a control or a form.

Syntax

object.BorderStyle [=BorderStyle]

The BorderStyle property syntax has these parts:

Part | Description
object | Required. A valid object.
BorderStyle | Optional. Specifies the border style.

Settings

The settings for BorderStyle are:

Value | Description
0 | The control has no visible border line.
1 | The control has a single-line border (default).

The default value for a ComboBox, Frame, Label, ListBox or TextBox is 0 (None). The default value for an Image is 1 (Single).

Remarks

For a Frame, the BorderStyle property is ignored if the SpecialEffect property is None.

You can use either BorderStyle or SpecialEffect to specify the border for a control, but not both. If you specify a nonzero value for one of these properties, the system sets the value of the other property to zero. For example, if you set BorderStyle to 1, the system sets SpecialEffect to zero (Flat). If you specify a nonzero value for SpecialEffect, the system sets BorderStyle to zero.

BorderStyle uses BorderColor to define the colors of its borders. To use the BorderColor property, the BorderStyle property must be set to a value other than 0.


BoundColumn Property

Identifies the source of data in a multicolumn ComboBox or ListBox.

Syntax

object.BoundColumn [= Variant]

The BoundColumn property syntax has these parts:

Part | Description
object | Required. A valid object.
Variant | Optional. Indicates how the BoundColumn value is selected.

Settings

The settings for Variant are:

Value | Description
0 | Assigns the value of the ListIndex property to the control.
1 or greater | Assigns the value from the specified column to the control. Columns are numbered from 1 when using this property (default).

Remarks

When the user chooses a row in a multicolumn ListBox or ComboBox, the BoundColumn property identifies which item from that row to store as the value of the control. For example, if each row contains 8 items and BoundColumn is 3, the system stores the information in the third column of the currently-selected row as the value of the object.

You can display one set of data to users but store different, associated values for the object by using the BoundColumn and the TextColumn properties. TextColumn identifies the column of data displayed in a ComboBox or ListBox; BoundColumn identifies the column of associated data values stored for the control. For example, you could set up a multicolumn ListBox that contains the names of holidays in one column and dates for the holidays in a second column. To present the holiday names to users, specify the first column as the TextColumn. To store the dates of the holidays, specify the second column as the BoundColumn.

If the control is bound to a data source, the value in the column specified by BoundColumn is stored in the data source named in the ControlSource property.

The ListIndex value retrieves the number of the selected row. For example, if you want to know the row of the selected item, set BoundColumn to 0 to assign the number of the selected row as the value of the control. Be sure to retrieve a current value, rather than relying on a previously saved value, if you are referencing a list whose contents might change.

The Column, List, and ListIndex properties all use zero-based numbering. That is, the value of the first item (column or row) is zero; the value of the second item is one, and so on. This means that if BoundColumn is set to 3, you could access the value stored in that column using the expression Column(2).


Cancel Property

Returns or sets a value indicating whether a CommandButton is the Cancel button on a form.

Syntax

object.Cancel [= Boolean]

The Cancel property syntax has these parts:

Part | Description
object | Required. A valid object.
Boolean | Optional. Whether the object is the Cancel button.

Settings

The settings for Boolean are:

Value | Description
True | The CommandButton is the Cancel button.
False | The CommandButton is not the Cancel button (default).

Remarks

A CommandButton or an object that acts like a command button can be designated as the default command button. For OLE container controls, the Cancel property is provided only for those objects that specifically behave as command buttons.

Only one CommandButton on a form can be the Cancel button. Setting Cancel to True for one command button automatically sets it to False for all other objects on the form. When a CommandButton's Cancel property is set to True and the form is the active form, the user can choose the command button by clicking it, pressing ESC, or pressing ENTER when the button has the focus.

A typical use of Cancel is to give the user the option of canceling uncommitted changes and returning the form to its previous state.

You should consider making the Cancel button the default button for forms that support operations that can't be undone (such as delete). To do this, set both Cancel and the Default property to True.


CanPaste Property

Specifies whether the Clipboard contains data that the object supports.

Syntax

object.CanPaste

The CanPaste property syntax has these parts:

Part | Description
object | Required. A valid object.

Return Values

The CanPaste property return values are:

Value | Description
True | The object can receive information pasted from the Clipboard.
False | The object cannot receive information pasted from the Clipboard.

Remarks

CanPaste is read-only.

If the Clipboard data is in a format that the object does not support, the CanPaste property is False. For example, if you try to paste a bitmap into an object that only supports text, CanPaste will be False.


CanRedo Property

Indicates whether the most recent Undo can be reversed.

Syntax

object.CanRedo

The CanRedo property syntax has these parts:

Part | Description
object | Required. A valid object.

Return Values

The CanRedo property syntax return values are:

Value | Description
True | The most recent Undo can be reversed.
False | The most recent Undo is irreversible.

Remarks

CanRedo is read-only.

To Redo an action means to reverse an Undo; it does not necessrily mean to repeat the last user action.


CanUndo Property

Indicates whether the last user action can be undone.

Syntax

object.CanUndo

The CanUndo property syntax has these parts:

Part | Description
object | Required. A valid object.

Return Values

The CanUndo property syntax return values are:

Value | Description
True | The most recent user action can be undone.
False | The most recent user action cannot be undone.

Remarks

CanUndo is read-only.

Many user actions can be undone with the Undo command. The CanUndo property indicates whether the most recent action can be undone.


Caption Property

Descriptive text that appears on an object to identify or describe it.

Syntax

object.Caption [= String]

The Caption property syntax has these parts:

Part | Description
object | Required. A valid object.
String | Optional. A string expression that evaluates to the text displayed as the caption.

Settings

The default setting for a control is a unique name based on the type of control. For example, CommandButton1 is the default caption for the first command button in a form.

Remarks

The text identifies or describes the object with which it is associated. For buttons and labels, the Caption property specifies the text that appears in the control. For Page and Tab objects, it specifies the text that appears on the tab. For the Explorer object, it specifies the text that appears in the explorer’s title bar.

If a control's caption is too long, the caption is truncated. If a form's caption is too long for the title bar, the title is displayed with an ellipsis.

The ForeColor property of the control determines the color of the text in the caption.

Tip If a control has both the Caption and AutoSize properties, setting AutoSize to True automatically adjusts the size of the control to frame the entire caption.


ClientHeight, ClientLeft, ClientTop, ClientWidth Properties

Define the dimensions and location of the display area of a TabStrip.

Syntax

object.ClientHeight [ =Single]

object.ClientLeft [ =Single]

object.ClientTop [ =Single]

object.ClientWidth [ =Single]

The ClientHeight, ClientLeft, ClientTop, and ClientWidth property syntaxes have these parts:

Part | Description
object | Required. A valid object.
Single | Optional. For ClientHeight and ClientWidth, specifies the height or width, in points, of the display area. For ClientLeft and ClientTop, specifies the distance, in points, from the top or left edge of the TabStrip's container.

Remarks

At run time, ClientLeft, ClientTop, ClientHeight, and ClientWidth automatically store the coordinates and dimensions of the TabStrip's internal area, which is shared by objects in the TabStrip.


Column Property

Specifies one or more items in a ListBox or ComboBox.

Syntax

object.Column( column, row ) [= Variant]

The Column property syntax has these parts:

Part | Description
object | Required. A valid object.
column | Optional. An integer with a range from 0 to one less than the total number of columns.
row | Optional. An integer with a range from 0 to one less than the total number of rows.
Variant | Optional. Specifies a single value, a column of values, or a two-dimensional array to load into a ListBox or ComboBox.

Settings

If you specify both the column and row values, Column reads or writes a specific item.

If you specify only the column value, the Column property reads or writes the specified column in the current row of the object. For example, MyListBox.Column (3) reads or writes the third column in MyListBox.

Column returns a Variant from the cursor. When a built-in cursor provides the value for Variant (such as when using the AddItem method), the value is a string. When an external cursor provides the value for Variant, formatting associated with the data is not included in the Variant.

Remarks

You can use Column to assign the contents of a combo box or list box to another control, such as a text box. For example, you can set the ControlSource property of a text box to the value in the second column of a list box.

If the user makes no selection when you refer to a column in a combo box or list box, the Column setting is Null. You can check for this condition by using the IsNull function.

You can also use Column to copy an entire two-dimensional array of values to a control. This syntax lets you quickly load a list of choices rather than individually loading each element of the list using AddItem.

Note When copying data from a two-dimensional array, Column transposes the contents of the array in the control so that the contents of ListBox1.Column(X, Y) is the same as MyArray(Y, X). You can also use List to copy an array without transposing it.


ColumnCount Property

Specifies the number of columns to display in a list box or combo box.

Syntax

object.ColumnCount [= Long]

The ColumnCount property syntax has these parts:

Part | Description
object | Required. A valid object.
Long | Optional. Specifies the number of columns to display.

Remarks

If you set the ColumnCount property for a list box to 3 on an employee form, one column can list last names, another can list first names, and the third can list employee ID numbers.

Setting ColumnCount to 0 displays zero columns, and setting it to -1 displays all the available columns. For an unbound data source, there is a 10-column limit (0 to 9).

You can use the ColumnWidths property to set the width of the columns displayed in the control.


ColumnHeads Property

Displays a single row of column headings for list boxes, combo boxes, and objects that accept column headings.

Syntax

object.ColumnHeads [= Boolean]

The ColumnHeads property syntax has these parts:

Part | Description
object | Required. A valid object.
Boolean | Optional. Specifies whether the column headings are displayed.

Settings

The settings for Boolean are:

Value | Description
True | Display column headings.
False | Do not display column headings (default).

Headings in combo boxes appear only when the list drops down.

Remarks

When the system uses the first row of data items as column headings, they can't be selected.


ColumnWidths Property

Specifies the width of each column in a multicolumn ComboBox or ListBox.

Syntax

object.ColumnWidths [= String]

The ColumnWidths property syntax has these parts:

Part | Description
object | Required. A valid object.
String | Optional. Sets the column width in points. A setting of –1 or blank results in a calculated width. A width of 0 hides a column. To specify a different unit of measurement, include the unit of measure. A value greater than 0 explicitly specifies the width of the column.

Settings

To separate column entries, use semicolons (;) as list separators. Or use the list separator specified in the Regional Settings section of the Windows Control Panel.

Any or all of the ColumnWidths property settings can be blank. You create a blank setting by typing a list separator without a preceding value.

If you specify a –1 in the property page, the displayed value in the property page is a blank.

To calculate column widths when ColumnWidths is blank or –1, the width of the control is divided equally among all columns of the list. If the sum of the specified column widths exceeds the width of the control, the list is left-aligned within the control and one or more of the rightmost columns are not displayed. Users can scroll the list using the horizontal scroll bar to display the rightmost columns.

The minimum calculated column width is 72 points (1 inch). To produce columns narrower than this, you must specify the width explicitly.

Unless specified otherwise, column widths are measured in points. To specify another unit of measure, include the units as part of the values. The following examples specify column widths in several units of measure and describe how the various settings would fit in a three-column list box that is 4 inches wide.

Setting | Effect
90;72;90 | The first column is 90 points (1.25 inch); the second column is 72 points (1 inch); the third column is 90 points.
6 cm;0;6 cm | The first column is 6 centimeters; the second column is hidden; the third column is 6 centimeters. Because part of the third column is visible, a horizontal scroll bar appears.
1.5 in;0;2.5 in | The first column is 1.5 inches, the second column is hidden, and the third column is 2.5 inches.
2 in;;2 in | The first column is 2 inches, the second column is 1 inch (default), and the third column is 2 inches. Because only half of the third column is visible, a horizontal scroll bar appears.
(Blank) | All three columns are the same width (1.33 inches).

Remarks

In a ComboBox, the system displays the column designated by the TextColumn property in the text box portion of the control. Setting TextColumn to –1 displays the first column that has a ColumnWidths value greater than 0.


ControlTipText Property

Specifies text that appears when the user briefly holds the mouse pointer over a control without clicking.

Syntax

object.ControlTipText [= String]

The ControlTipText property syntax has these parts:

Part | Description
object | Required. A valid object.
String | Optional. The text that appears when the user holds the mouse pointer over a control.

Remarks

The ControlTipText property lets you give users tips about a control in a running form. The property can be set during design time but only appears by the control during run time.

The default value of ControlTipText is an empty string. When the value of ControlTipText is set to an empty string, no tip is available for that control.


Count Property

Returns the number of objects in a collection.

Syntax

object.Count

The Count property syntax has these parts:

Part | Description
object | Required. A valid object.

Remarks

The Count property is read only.

Note that the index value for the first page or tab of a collection is zero, the value for the second page or tab is one, and so on. For example, if a MultiPage contains two pages, the indexes of the pages are 0 and 1, and the value of Count is 2.


CurLine Property

Specifies the current line of a control.

Syntax

object.CurLine [= Long]

The CurLine property syntax has these parts:

Part | Description
object | Required. A valid object.
Long | Optional. Specifies the current line of a control.

Remarks

The current line of a control is the line that contains the insertion point. The number of the first line is 0.

The CurLine property is valid when the control has focus.


CurTargetX Property

Retrieves the preferred horizontal position of the insertion point in a multiline TextBox or ComboBox.

Syntax

object.CurTargetX

The CurTargetX property syntax has these parts:

Part | Description
object | Required. A valid object.

Return Values

The CurTargetX property retrieves the preferred position, measured in himetric units. A himetric is 0.0001 meter.

Remarks

The target position is relative to the left edge of the control. If the length of a line is less than the value of the CurTargetX property, you can place the insertion point at the end of the line. The value of CurTargetX changes when the user sets the insertion point or when the CurX property is set. CurTargetX is read-only.

The return value is valid when the object has focus

You can use CurTargetX and CurX to move the insertion point as the user scrolls through the contents of a multiline TextBox or ComboBox. When the user moves the insertion point to another line of text by scrolling the content of the object, CurTargetX specifies the preferred position for the insertion point. CurX is set to this value if the line of text is longer than the value of CurTargetX. Otherwise, CurX is set to the end of the line of text.


CurX Property

Specifies the current horizontal position of the insertion point in a multiline TextBox or ComboBox.

Syntax

object.CurX [= Long]

The CurX property syntax has these parts:

Part | Description
object | Required. A valid object.
Long | Optional. Indicates the current position, measured in himetrics. A himetric is 0.0001 meter.

Remarks

The CurX property applies to a multiline TextBox or ComboBox. The return value is valid when the object has the focus

You can use CurTargetX and CurX to position the insertion point as the user scrolls through the contents of a multiline TextBox or ComboBox. When the user moves the insertion point to another line of text by scrolling the content of the object, CurTargetX specifies the preferred position for the insertion point. CurX is set to this value if the line of text is longer than the value of CurTargetX. Otherwise, CurX is set to the end of the line of text.


Cycle Property

Specifies the action to take when the user leaves the last control on a Frame or Page.

Syntax

object.Cycle [=Cycle]

The Cycle property syntax has these parts:

Part | Description
object | Required. A valid object.
Cycle | Optional. Specifies whether cycling includes controls nested in a Frame or MultiPage.

Settings

The settings for Cycle are:

Value | Description
0 | Cycles through the controls on the form and the controls of the Frame and MultiPage controls that are currently displayed on the form.
2 | Cycles through the controls on the form, Frame, or MultiPage. The focus stays within the form, Frame, or MultiPage until the focus is explicitly set to a control outside the form, Frame, or MultiPage.

If you specify a non-integer value for Cycle, the value is rounded up to the nearest integer.

Remarks

The tab order identifies the order in which controls receive the focus as the user tabs through a form or subform. The Cycle property determines the action to take when a user tabs from the last control in the tab order.

The 0 setting transfers the focus to the first control of the next Frame or MultiPage on the form when the user tabs from the last control in the tab order.

The 2 setting transfers the focus to the first control of the same form, Frame, or MultiPage when the user tabs from the last control in the tab order.


Default Property

Designates the default CommandButton on a form.

Syntax

object.Default [= Boolean]

The Default property syntax has these parts:

Part | Description
object | Required. A valid object.
Boolean | Optional. Whether the command button is the default.

Settings

The settings for Boolean are:

Value | Description
True | The CommandButton is the default button.
False | The CommandButton is not the default button (default).

Remarks

A CommandButton or an object that acts like a command button can be designated as the default command button. Only one object on a form can be the default command button. Setting the Default property to True for one object automatically sets it to False for all other objects on the form.

To choose the default command button on an active form, the user can click the button, or press ENTER when no other CommandButton has the focus.

Default is provided for OLE container controls that specifically act like CommandButton controls.

Tip You should consider making the Cancel button the default button for forms that support operations that can't be undone (such as delete). To do this, set both Default and the Cancel property to True.


Delay Property

Specifies the delay on a SpinButton or ScrollBar.

Syntax

object.Delay [= Long]

The Delay property syntax has these parts:

Part | Description
object | Required. A valid object.
Long | Optional. The delay, in milliseconds, between events.

Remarks

The Delay property affects the amount of time between consecutive SpinUp, SpinDown, and Change events generated when the user clicks and holds down a button on a SpinButton or ScrollBar. The first event occurs immediately. The delay to the second occurrence of the event is five times the value of the specified Delay. This initial lag makes it easy to generate a single event rather than a stream of events.

After the initial lag, the interval between events is the value specified for Delay.

The default value of Delay is 50 milliseconds. This means the object initiates the first event after 250 milliseconds (5 times the specified value) and initiates each subsequent event after 50 milliseconds.


DragBehavior Property

Specifies whether the system enables the drag-and-drop feature for a TextBox or ComboBox.

Syntax

object.DragBehavior [=DragBehavior]

The DragBehavior property syntax has these parts:

Part | Description
object | Required. A valid object.
DragBehavior | Optional. Specifies whether the drag-and-drop feature is enabled.

Settings

The settings for DragBehavior are:

Value | Description
0 | Does not allow a drag-and-drop action (default).
1 | Allows a drag-and-drop action.

Remarks

If the DragBehavior property is enabled, dragging in a text box or combo box starts a drag-and-drop operation on the selected text. If DragBehavior is disabled, dragging in a text box or combo box selects text.

The drop-down portion of a ComboBox does not support drag-and-drop processes, nor does it support selection of list items within the text.

DragBehavior has no effect on a ComboBox whose Style property is set to 2.

Note You can combine the effects of the EnterFieldBehavior property and DragBehavior to create a large number of text box styles.


DropButtonStyle Property

Specifies the symbol displayed on the drop button in a ComboBox.

Syntax

object.DropButtonStyle [=DropButtonStyle]

The DropButtonStyle property syntax has these parts:

Part | Description
object | Required. A valid object.
DropButtonStyle | Optional. The appearance of the drop button.

Settings

The settings for DropButtonStyle are:

Value | Description
0 | Displays a plain button, with no symbol.
1 | Displays a down arrow (default).
2 | Displays an ellipsis (...).
3 | Displays a horizontal line like an underscore character.

Remarks

The recommended setting for showing items in a list is 1.


Enabled Property

Specifies whether a control can receive the focus and respond to user-generated events.

Syntax

object.Enabled [= Boolean]

The Enabled property syntax has these parts:

Part | Description
object | Required. A valid object.
Boolean | Optional. Whether the object can respond to user-generated events.

Settings

The settings for Boolean are:

Value | Description
True | The control can receive the focus and respond to user-generated events, and is accessible through code (default).
False | The user cannot interact with the control by using the mouse, keystrokes, accelerators, or hotkeys. The control is generally still accessible through code.

Remarks

Use the Enabled property to enable and disable controls. A disabled control appears dimmed, while an enabled control does not. Also, if a control displays a bitmap, the bitmap is dimmed whenever the control is dimmed. If Enabled is False for an Image, the control does not initiate events but does not appear dimmed.

The Enabled and Locked properties work together to achieve the following effects:

  • If Enabled and Locked are both True, the control can receive focus and appears normally (not dimmed) in the form. The user can copy, but not edit, data in the control.
  • If Enabled is True and Locked is False, the control can receive focus and appears normally in the form. The user can copy and edit data in the control.
  • If Enabled is False and Locked is True, the control cannot receive focus and is dimmed in the form. The user can neither copy nor edit data in the control.
  • If Enabled and Locked are both False, the control cannot receive focus and is dimmed in the form. The user can neither copy nor edit data in the control.

You can combine the settings of the Enabled and the TabStop properties to prevent the user from selecting a command button with TAB, while still allowing the user to click the button. Setting TabStop to False means that the command button won't appear in the tab order. However, if Enabled is True, then the user can still click the command button, as long as TakeFocusOnClick is set to True.

When the user tabs into an enabled MultiPage or TabStrip, the first page or tab in the control receives the focus. If the first page or tab of a MultiPage or TabStrip is disabled, the first enabled page or tab of that control receives the focus. If all pages or tabs of a MultiPage or TabStrip are disabled, the control is disabled and cannot receive the focus.

If a Frame is disabled, all controls that it contains are disabled.

Clicking a disabled ListBox does not initiate the Click event.


EnterFieldBehavior Property

Specifies the selection behavior when entering a TextBox or ComboBox.

Syntax

object.EnterFieldBehavior [=EnterFieldBehavior]

The EnterFieldBehavior property syntax has these parts:

Part | Description
object | Required. A valid object.
EnterFieldBehavior | Optional. The desired selection behavior.

Settings

The settings for EnterFieldBehavior are:

Value | Description
0 | Selects the entire contents of the edit region when entering the control (default).
1 | Leaves the selection unchanged. Visually, this uses the selection that was in effect the last time the control was active.

Remarks

The EnterFieldBehavior property controls the way text is selected when the user tabs to the control, not when the control receives focus as a result of the SetFocus method. Following SetFocus, the contents of the control are not selected and the insertion point appears after the last character in the control's edit region.

Note You can combine the effects of the EnterFieldBehavior property and DragBehavior to create a large number of text box styles.


EnterKeyBehavior Property

Defines the effect of pressing ENTER in a TextBox.

Syntax

object.EnterKeyBehavior [= Boolean]

The EnterKeyBehavior property syntax has these parts:

Part | Description
object | Required. A valid object.
Boolean | Optional. Specifies the effect of pressing ENTER.

Settings

The settings for Boolean are:

Value | Description
True | Pressing ENTER creates a new line.
False | Pressing ENTER moves the focus to the next object in the tab order (default).

Remarks

The EnterKeyBehavior and MultiLine properties are closely related. The values described above only apply if MultiLine is True. If MultiLine is False, pressing ENTER always moves the focus to the next control in the tab order regardless of the value of EnterKeyBehavior.

The effect of pressing CTRL+ENTER also depends on the value of MultiLine. If MultiLine is True, pressing CTRL+ENTER creates a new line regardless of the value of EnterKeyBehavior. If MultiLine is False, pressing CTRL+ENTER has no effect.


ForeColor Property

Specifies the foreground color of an object.

Syntax

object.ForeColor [= Long]

The ForeColor property syntax has these parts:

Part | Description
object | Required. A valid object.
Long | Optional. A value or constant that determines the foreground color of an object.

Settings

You can use any integer that represents a valid color. You can also specify a color by using the RGB function with red, green, and blue color components. The value of each color component is an integer that ranges from zero to 255. For example, you can specify teal blue as the integer value 4966415 or as red, green, and blue color components 15, 200, 75, as shown in the following example.

RGB(15,200,75)

Remarks

Use the ForeColor property for controls on forms to make them easy to read or to convey a special meaning. For example, if a text box reports the number of units in stock, you can change the color of the text when the value falls below the reorder level.

For a ScrollBar or SpinButton, ForeColor sets the color of the arrows. For a Frame, ForeColor changes the color of the caption. For a Font object, ForeColor determines the color of the text.


GroupName Property

Creates a group of mutually exclusive OptionButton controls.

Syntax

object.GroupName [= String]

The GroupName property syntax has these parts:

Part | Description
object | Required. A valid OptionButton.
String | Optional. The name of the group that includes the OptionButton. Use the same setting for all buttons in the group. The default setting is an empty string.

Remarks

To create a group of mutually exclusive OptionButton controls, you can put the buttons in a Frame on your form, or you can use the GroupName property. GroupName is more efficient for the following reasons:

  • You do not have to include a Frame for each group. By not using a Frame, you reduce the number of controls on the form, and in turn, improve performance and reduce the size of the form.
  • You have more design flexibility. If you use a Frame to create the group, all the buttons must be inside the Frame. If you want more than one group, you must have one Frame for each group. However, if you use GroupName to create the group, the group can include option buttons anywhere on the form. If you want more than one group, specify a unique name for each group; you can still place the individual controls anywhere on the form.
  • You can create buttons with transparent backgrounds, which can improve the visual appearance of your form. The Frame is not a transparent control.

Regardless of which method you use to create the group of buttons, clicking one button in a group sets all other buttons in the same group to False. All option buttons with the same GroupName within a single container are mutually exclusive. You can use the same group name in two containers, but doing so creates two groups (one in each container) rather than one group that includes both containers.

For example, assume your form includes some option buttons and a MultiPage that also includes option buttons. The option buttons on the MultiPage are one group and the buttons on the form are another group. The two groups do not affect each other. Changing the setting of a button on the MultiPage does not affect the buttons on the form.


Height, Width Properties

The height or width, in points, of an object.

Syntax

object.Height [= Single]

object.Width [= Single]

The Height and Width property syntaxes have these parts:

Part | Description
object | Required. A valid object.
Single | Optional. A numeric expression specifying the dimensions of an object.

Remarks

The Height and Width properties are automatically updated when you move or size a control. If you specify a setting for the Left or Top property that is less than zero, that value will be used to calculate the height or width of the control, but a portion of the control will not be visible on the form.

If you move a control from one part of a form to another, the setting of Height or Width only changes if you size the control as you move it. The settings of the control's Left and Top properties will change to reflect the control's new position relative to the edges of the form that contains it.

The value assigned to Height or Width must be greater than or equal to zero. For most systems, the recommended range of values is from 0 to +32,767. Higher values may also work depending on your system configuration.

For most systems, the recommended range of values for Left and Top is from -32,767 to +32,767. Other values may also work depending on your system configuration. For a ComboBox, values of Left and Top apply to the text portion of the control, not to the list portion. When you move or size a control, its new Left setting is automatically entered in the property sheet. When you print a form, the control's horizontal or vertical location is determined by its Left or Top setting.


HideSelection Property

Specifies whether selected text remains highlighted when a control does not have the focus.

Syntax

object.HideSelection [= Boolean]

The HideSelection property syntax has these parts:

Part | Description
object | Required. A valid object.
Boolean | Optional. Whether the selected text remains highlighted even when the control does not have the focus.

Settings

The settings for Boolean are:

Value | Description
True | Selected text is not highlighted unless the control has the focus (default).
False | Selected text always appears highlighted.

Remarks

You can use the HideSelection property to maintain highlighted text when another form or a dialog box receives the focus, such as in a spell-checking procedure.


IMEMode Property

This feature is available in the Simplified Chinese, Traditional Chinese, Korean, and Japanese language versions of Microsoft Office.

Specifies the default run-time mode of the Input Method Editor (IME) for a control. This property applies only to applications written for Asian languages and is ignored in other applications.

Syntax

object.IMEMode [= fmIMEMode]

The IMEMode property syntax has these parts:

Part | Description
object | Required. A valid object.
fmIMEMode | Optional. The mode of the Input Method Editor (IME).

Settings

The settings for fmIMEMode are:

Value | Description
0 | Does not control IME (default).
1 | IME on.
2 | IME off. English mode.
3 | IME off. User can’t turn on IME by keyboard.
4 | IME on with Full-width Hiragana mode.
5 | IME on with Full-width Katakana mode.
6 | IME on with Half-width Katakana mode.
7 | IME on with Full-width Alphanumeric mode.
8 | IME on with Half-width Alphanumeric mode.
9 | IME on with Full-width Hangul mode.
10 | IME on with Half-width Hangul mode.

A setting of 0 indicates that the mode of the IME does not change when the control receives focus at run time. For any other value, the mode of the IME is set to the value specified by the IMEMode property when the control receives focus at run time.


Index Property

The position of a Tab object within a Tabs collection or a Page object in a Pages collection.

Syntax

object.Index [= Integer]

The Index property syntax has these parts:

Part | Description
object | Required. A valid object.
Integer | Optional. The index of the currently selected Tab object.

Remarks

The Index property specifies the order in which tabs appear. Changing the value of Index visually changes the order of Pages in a MultiPage or Tabs on a TabStrip. The index value for the first page or tab is zero, the index value of the second page or tab is one, and so on.

In a MultiPage, Index refers to a Page as well as the page's Tab. In a TabStrip, Index refers to the tab only.


InsideHeight, InsideWidth Properties

InsideHeight returns the height, in points, of the client region inside a Frame. InsideWidth returns the width, in points, of the client region inside a Frame.

Syntax

object.InsideHeight

object.InsideWidth

The InsideHeight and InsideWidth property syntaxes have these parts:

Part | Description
object | Required. A valid object.

Remarks

The InsideHeight and InsideWidth properties are read-only.


IntegralHeight Property

Indicates whether a ListBox or TextBox displays full lines of text in a list or partial lines.

Syntax

object.IntegralHeight [= Boolean]

The IntegralHeight property syntax has these parts:

Part | Description
object | Required. A valid object.
Boolean | Optional. Whether the list displays partial lines of text.

Settings

The settings for Boolean are:

Value | Description
True | The list resizes itself to display only complete items (default).
False | The list does not resize itself even if the item is too tall to display completely.

Remarks

The IntegralHeight property relates to the height of the list, just as the AutoSize property relates to the width of the list.

If IntegralHeight is True, the list box automatically resizes when necessary to show full rows. If False, the list remains a fixed size; if items are taller than the available space in the list, the entire item is not shown.


KeepScrollBarsVisible Property

Specifies whether scroll bars remain visible when not required.

Syntax

object.KeepScrollBarsVisible [=ScrollBars]

The KeepScrollBarsVisible property syntax has these parts:

Part | Description
object | Required. A valid object.
ScrollBars | Optional. Where scroll bars are displayed.

Settings

The settings for ScrollBars are:

Value | Description
0 | Displays no scroll bars.
1 | Displays a horizontal scroll bar.
2 | Displays a vertical scroll bar.
3 | Displays both a horizontal and a vertical scroll bar (default).

Remarks

If the visible region is large enough to display all the controls on an object such as a Page object, scroll bars are not required. The KeepScrollBarsVisible property determines whether the scroll bars remain visible when they are not required.

If the scroll bars are visible when they are not required, they appear normal in size, and the scroll box fills the entire width or height of the scroll bar.

If the KeepScrollBarsVisible property is True, any scroll bar on a form or page is always visible, regardless of whether the object's contents fit within the object's borders.


LargeChange Property

Specifies the amount of movement that occurs when the user clicks between the scroll box and scroll arrow.

Syntax

object.LargeChange [= Long]

The LargeChange property syntax has these parts:

Part | Description
object | Required. A valid object.
Long | Optional. An integer that specifies the amount of change to the Value property.

Remarks

The LargeChange property applies only to the ScrollBar. It does not apply to the scrollbars in other controls such as a TextBox or a drop-down ComboBox.

The value of LargeChange is the amount by which the ScrollBar's Value property changes when the user clicks the area between the scroll box and scroll arrow. The direction of the movement is always toward the place where the user clicks. For example, in a horizontal ScrollBar, clicking to the left of the scroll box moves the scroll box to the left. In a vertical ScrollBar, clicking above the scroll box moves the scroll box up.

LargeChange does not have units. Any integer is a valid setting for LargeChange. The recommended range of values is from –32,767 to +32,767, and the value must be between the values of the Max and Min properties of the ScrollBar.


Left, Top Properties

The distance between a control and the left or top edge of the form that contains it.

Syntax

object.Left [= Single]

object.Top [= Single]

The Left and Top property syntaxes have these parts:

Part | Description
object | Required. A valid object.
Single | Optional. A numeric expression specifying the coordinates of an object.

Settings

Setting the Left or Top property to 0 places the control's edge at the left or top edge of its container.

Remarks

For most systems, the recommended range of values for Left and Top is from -32,767 to +32,767. Other values may also work depending on your system configuration. For a ComboBox, values of Left and Top apply to the text portion of the control, not to the list portion. When you move or size a control, its new Left setting is automatically entered in the property sheet. When you print a form, the control's horizontal or vertical location is determined by its Left or Top setting.

The Height and Width properties are automatically updated when you move or size a control. If you specify a setting for the Left or Top property that is less than zero, that value will be used to calculate the height or width of the control, but a portion of the control will not be visible on the form.

If you move a control from one part of a form to another, the setting of Height or Width only changes if you size the control as you move it. The settings of the control's Left and Top properties will change to reflect the control's new position relative to the edges of the form that contains it.

The value assigned to Height or Width must be greater than or equal to zero. For most systems, the recommended range of values is from 0 to +32,767. Higher values may also work depending on your system configuration.


LineCount Property

Returns the number of text lines in a TextBox or ComboBox.

Syntax

object.LineCount

The LineCount property syntax has these parts:

Part | Description
object | Required. A valid object.

Remarks

The LineCount property is read-only.

Note A ComboBox will only have one line.


List Property

Returns or sets the list entries of a ListBox or ComboBox.

Syntax

object.List( row, column ) [= Variant]

The List property syntax has these parts:

Part | Description
object | Required. A valid object.
row | Required. An integer with a range from 0 to one less than the number of entries in the list.
column | Required. An integer with a range from 0 to one less than the number of columns.
Variant | Optional. The contents of the specified entry in the ListBox or ComboBox.

Settings

Row and column numbering begins with zero. That is, the row number of the first row in the list is zero; the column number of the first column is zero. The number of the second row or column is 1, and so on.

Remarks

The List property works with the ListCount and ListIndex properties. Use List to access list items. A list is a variant array; each item in the list has a row number and a column number.

Initially, ComboBox and ListBox contain empty lists.

Note To specify items you want to display in a ComboBox or ListBox, use the AddItem method. To remove items, use the RemoveItem method.

Use List to copy an entire two-dimensional array of values to a control. Use AddItem to load a one-dimensional array or to load an individual element.


ListCount Property

Returns the number of list entries in a control.

Syntax

object.ListCount

The ListCount property syntax has these parts:

Part | Description
object | Required. A valid object.

Remarks

The ListCount property is read-only. ListCount is the number of rows over which you can scroll. ListCount is always one greater than the largest value for the ListIndex property, because index numbers begin with 0 and the count of items begins with 1. If no item is selected, ListCount is 0 and ListIndex is –1.


ListIndex Property

Identifies the currently selected item in a ListBox or ComboBox.

Syntax

object.ListIndex [= Variant]

The ListIndex property syntax has these parts:

Part | Description
object | Required. A valid object.
Variant | Optional. The currently selected item in the control.

Remarks

The ListIndex property contains an index of the selected row in a list. Values of ListIndex range from –1 to one less than the total number of rows in a list (that is, ListCount – 1). When no rows are selected, ListIndex returns –1. When the user selects a row in a ListBox or ComboBox, the system sets the ListIndex value. The ListIndex value of the first row in a list is 0, the value of the second row is 1, and so on.

Note If you use the MultiSelect property to create a ListBox that allows multiple selections, the Selected property of the ListBox (rather than the ListIndex property) identifies the selected rows. The Selected property is an array with the same number of values as the number of rows in the ListBox. For each row in the list box, Selected is True if the row is selected and False if it is not. In a ListBox that allows multiple selections, ListIndex returns the index of the row that has focus, regardless of whether that row is currently selected.

The ListIndex value is also available by setting the BoundColumn property to 0 for a combo box or list box. If BoundColumn is 0, the underlying data source to which the combo box or list box is bound contains the same list index value as ListIndex.


ListRows Property

Specifies the maximum number of rows to display in the list.

Syntax

object.ListRows [= Long]

The ListRows property syntax has these parts:

Part | Description
object | Required. A valid object.
Long | Optional. An integer indicating the maximum number of rows. The default value is 8.

Remarks

If the number of items in the list exceeds the value of the ListRows property, a scroll bar appears at the right edge of the list-box portion of the combo box.


ListStyle Property

Specifies the visual appearance of the list in a ListBox or ComboBox.

Syntax

object.ListStyle [=ListStyle]

The ListStyle property syntax has these parts:

Part | Description
object | Required. A valid object.
ListStyle | Optional. The visual style of the list.

Settings

The settings for ListStyle are:

Value | Description
0 | Looks like a regular list box, with the background of items highlighted.
1 | Shows option buttons, or check boxes for a multi-select list (default). When the user selects an item from the group, the option button associated with that item is selected and the option buttons for the other items in the group are deselected.

Remarks

The ListStyle property lets you change the visual presentation of a ListBox or ComboBox. By specifying a setting other than 0, you can present the contents of either control as a group of individual items, with each item including a visual cue to indicate whether it is selected.

If the control supports a single selection (the MultiSelect property is set to 0), the user can press one button in the group. If the control supports multi-select, the user can press two or more buttons in the group.


ListWidth Property

Specifies the width of the list in a ComboBox.

Syntax

object.ListWidth [= Variant]

The ListWidth property syntax has these parts:

Part | Description
object | Required. A valid object.
Variant | Optional. The width of the list. A value of zero makes the list as wide as the ComboBox. The default value is to make the list as wide as the text portion of the control.

Remarks

If you want to display a multicolumn list, enter a value that will make the list box wide enough to fit all the columns.

Tip When designing combo boxes, be sure to leave enough space to display your data and for a vertical scroll bar.


Locked Property

Specifies whether a control can be edited.

Syntax

object.Locked [= Boolean]

The Locked property syntax has these parts:

Part | Description
object | Required. A valid object.
Boolean | Optional. Whether the control can be edited.

Settings

The settings for Boolean are:

Value | Description
True | You can't edit the value.
False | You can edit the value (default).

Remarks

When a control is locked and enabled, it can still initiate events and can still receive the focus.

The Enabled and Locked properties work together to achieve the following effects:

  • If Enabled and Locked are both True, the control can receive focus and appears normally (not dimmed) in the form. The user can copy, but not edit, data in the control.
  • If Enabled is True and Locked is False, the control can receive focus and appears normally in the form. The user can copy and edit data in the control.
  • If Enabled is False and Locked is True, the control cannot receive focus and is dimmed in the form. The user can neither copy nor edit data in the control.
  • If Enabled and Locked are both False, the control cannot receive focus and is dimmed in the form. The user can neither copy nor edit data in the control.


MatchEntry Property

Returns or sets a value indicating how a ListBox or ComboBox searches its list as the user types.

Syntax

object.MatchEntry [=MatchEntry]

The MatchEntry property syntax has these parts:

Part | Description
object | Required. A valid object.
MatchEntry | Optional. The rule used to match entries in the list.

Settings

The settings for MatchEntry are:

Value | Description
0 | Basic matching. The control searches for the next entry that starts with the character entered. Repeatedly typing the same letter cycles through all entries beginning with that letter.
1 | Extended matching. As each character is typed, the control searches for an entry matching all characters entered (default).
2 | No matching.

Remarks

The MatchEntry property searches entries from the TextColumn property of a ListBox or ComboBox.

The control searches the column identified by TextColumn for an entry that matches the user's typed entry. Upon finding a match, the row containing the match is selected, the contents of the column are displayed, and the contents of its BoundColumn property become the value of the control. If the match is unambiguous, finding the match initiates the Click event.

The control initiates the Click event as soon as the user types a sequence of characters that match exactly one entry in the list. As the user types, the entry is compared with the current row in the list and with the next row in the list. When the entry matches only the current row, the match is unambiguous.

In Microsoft Forms, this is true regardless of whether the list is sorted. This means the control finds the first occurrence that matches the entry, based on the order of items in the list. For example, entering either "abc" or "bc" will initiate the Click event for the following list:

abcde
bcdef
abcxyz
bchij

Note that in either case, the matched entry is not unique; however, it is sufficiently different from the adjacent entry that the control interprets the match as unambiguous and initiates the Click event.


MatchFound Property

Indicates whether the text that a user has typed into a ComboBox matches any of the entries in the list.

Syntax

object.MatchFound

The MatchFound property syntax has these parts:

Part | Description
object | Required. A valid object.

Return Values

The MatchFound property return values are:

Value | Description
True | The contents of the Value property matches one of the records in the list.
False | The contents of Value does not match any of the records in the list (default).

Remarks

The MatchFound property is read-only. It is not applicable when the MatchEntry property is set to 2.


MatchRequired Property

Specifies whether a value entered in the text portion of a ComboBox must match an entry in the existing list portion of the control. The user can enter non-matching values, but may not leave the control until a matching value is entered.

Syntax

object.MatchRequired [= Boolean]

The MatchRequired property syntax has these parts:

Part | Description
object | Required. A valid object.
Boolean | Optional. Whether the text entered must match an existing item in the list.

Settings

The settings for Boolean are:

Value | Description
True | The text entered must match an existing list entry.
False | The text entered can be different from all existing list entries (default).

Remarks

If the MatchRequired property is True, the user cannot exit the ComboBox until the text entered matches an entry in the existing list. MatchRequired maintains the integrity of the list by requiring the user to select an existing entry.

Note Not all containers enforce this property.


Max, Min Properties

Specify the maximum and minimum acceptable values for the Value property of a ScrollBar or SpinButton.

Syntax

object.Max [= Long]

object.Min [= Long]

The Max and Min property syntaxes have these parts:

Part | Description
object | Required. A valid object.
Long | Optional. A numeric expression specifying the maximum or minimum Value property setting.

Remarks

Clicking a SpinButton or moving the scroll box in a ScrollBar changes the Value property of the control.

The value for the Max property corresponds to the lowest position of a vertical ScrollBar or the rightmost position of a horizontal ScrollBar. The value for the Min property corresponds to the highest position of a vertical ScrollBar or the leftmost position of a horizontal ScrollBar.

Any integer is an acceptable setting for this property. The recommended range of values is from –32,767 to +32,767. The default value is 1.

Note Min and Max refer to locations, not to relative values, on the ScrollBar. That is, the value of Max could be less than the value of Min. If this is the case, moving toward the Max (bottom) position means decreasing Value; moving toward the Min (top) position means increasing Value.


MaxLength Property

Specifies the maximum number of characters a user can enter in a TextBox or ComboBox.

Syntax

object.MaxLength [= Long]

The MaxLength property syntax has these parts:

Part | Description
object | Required. A valid object.
Long | Optional. An integer indicating the allowable number of characters.

Remarks

Setting the MaxLength property to 0 indicates there is no limit other than that created by memory constraints.


MouseIcon Property

Assigns a custom icon to an object.

Syntax

object.MouseIcon = LoadPicture( pathname )

The MouseIcon property syntax has these parts:

Part | Description
object | Required. A valid object.
pathname | Required. A string expression specifying the path and filename of the file containing the custom icon.

Remarks

The MouseIcon property is valid when the MousePointer property is set to 99. The mouse icon of an object is the image that appears when the user moves the mouse across that object.

To assign an image for the mouse pointer, you can either assign a picture to the MouseIcon property or load a picture from a file using the LoadPicture function.


MousePointer Property

Specifies the type of pointer displayed when the user positions the mouse over a particular object.

Syntax

object.MousePointer [=MousePointer]

The MousePointer property syntax has these parts:

Part | Description
object | Required. A valid object.
MousePointer | Optional. The shape you want for the mouse pointer.

Settings

The settings for MousePointer are:

Value | Description
0 | Standard pointer. The image is determined by the object (default).
1 | Arrow.
2 | Cross-hair pointer.
3 | I-beam.
6 | Double arrow pointing northeast and southwest.
7 | Double arrow pointing north and south.
8 | Double arrow pointing northwest and southeast.
9 | Double arrow pointing west and east.
10 | Up arrow.
11 | Hourglass.
12 | "Not" symbol (circle with a diagonal line) on top of the object being dragged. Indicates an invalid drop target.
13 | Arrow with an hourglass.
14 | Arrow with a question mark.
15 | Size all cursor (arrows pointing north, south, east, and west).
99 | Uses the icon specified by the MouseIcon property.

Remarks

Use the MousePointer property when you want to indicate changes in functionality as the mouse pointer passes over controls on a form. For example, the hourglass setting (11) is useful to indicate that the user must wait for a process or operation to finish.

Some icons vary depending on system settings, such as the icons associated with desktop themes.


MultiLine Property

Specifies whether a control can accept and display multiple lines of text.

Syntax

object.MultiLine [= Boolean]

The MultiLine property syntax has these parts:

Part | Description
object | Required. A valid object.
Boolean | Optional. Whether the control supports more than one line of text.

Settings

The settings for Boolean are:

Value | Description
True | The text is displayed across multiple lines (default).
False | The text is not displayed across multiple lines.

Remarks

A multiline TextBox allows absolute line breaks and adjusts its quantity of lines to accommodate the amount of text it holds. If needed, a multiline control can have vertical scroll bars.

A single-line TextBox doesn't allow absolute line breaks and doesn't use vertical scroll bars.

For controls that support the MultiLine property as well as the WordWrap property, WordWrap is ignored when MultiLine is False.

Single-line controls ignore the value of the WordWrap property.

Note If you change MultiLine to False in a multiline TextBox, all the characters in the TextBox will be combined into one line, including non-printing characters (such as carriage returns and new-lines).

The EnterKeyBehavior and MultiLine properties are closely related. The EnterKeyBehavior values of True and False only apply if MultiLine is True. If MultiLine is False, pressing ENTER always moves the focus to the next control in the tab order regardless of the value of EnterKeyBehavior.

The effect of pressing CTRL+ENTER also depends on the value of MultiLine. If MultiLine is True, pressing CTRL+ENTER creates a new line regardless of the value of EnterKeyBehavior. If MultiLine is False, pressing CTRL+ENTER has no effect.

The TabKeyBehavior and MultiLine properties are closely related. The values described above only apply if MultiLine is True. If MultiLine is False, pressing TAB always moves the focus to the next control in the tab order regardless of the value of TabKeyBehavior.

The effect of pressing CTRL+TAB also depends on the value of MultiLine. If MultiLine is True, pressing CTRL+TAB creates a new line regardless of the value of TabKeyBehavior. If MultiLine is False, pressing CTRL+TAB has no effect.


MultiRow Property

Specifies whether the control has more than one row of tabs.

Syntax

object.MultiRow [= Boolean]

The MultiRow property syntax has these parts:

Part | Description
object | Required. A valid object.
Boolean | Optional. Whether the control has more than one row of tabs.

Settings

The settings for Boolean are:

Value | Description
True | Allows more than one row of tabs.
False | Restricts tabs to a single row (default).

Remarks

The width and number of tabs determines the number of rows. Changing the control's size also changes the number of rows. This allows the developer to resize the control and ensure that tabs wrap to fit the control. If the MultiRow property is False, then truncation occurs if the width of the tabs exceeds the width of the control.

If MultiRow is False and tabs are truncated, there will be a small scroll bar on the TabStrip to allow scrolling to the other tabs or pages.


MultiSelect Property

Indicates whether the object permits multiple selections.

Syntax

object.MultiSelect [=MultiSelect]

The MultiSelect property syntax has these parts:

Part | Description
object | Required. A valid object.
MultiSelect | Optional. The selection mode that the control uses.

Settings

The settings for MultiSelect are:

Value | Description
0 | Only one item can be selected (default).
1 | Pressing the SPACEBAR or clicking selects or deselects an item in the list.
2 | Pressing SHIFT and clicking the mouse, or pressing SHIFT and one of the arrow keys, extends the selection from the previously selected item to the current item. Pressing CTRL and clicking the mouse selects or deselects an item.

Remarks

When the MultiSelect property is set to Extended or Simple, you must use the list box's Selected property to determine the selected items. Also, the Value property of the control is always Null.

The ListIndex property returns the index of the row with the keyboard focus.<P>


Name Property

Specifies the name of a control or an object, or the name of a font to associate with a Font object.

Syntax

For Font
Font.Name [= String]

For all other controls and objects
object.Name [= String]

The Name property syntax has these parts:

Part | Description
object | Required. A valid object.
String | Optional. The name you want to assign to the font or control.

Settings

Guidelines for assigning a string to Name, such as the maximum length of the name, vary from one application to another.

Remarks

For objects, the default value of Name consists of the object's class name followed by an integer. For example, the default name for the first TextBox you place on a form is TextBox1. The default name for the second TextBox is TextBox2.

You can set the Name property for a control from the control's property sheet or, for controls added at run time, by using program statements. If you add a control at design time, you cannot modify its Name property at run time.

Each control added to a form at design time must have a unique name.

For Font objects, Name identifies a particular typeface to use in the text portion of a control, object, or form. The font's appearance on screen and in print may differ, depending on your computer and printer. If you select a font that your system can't display or that isn't installed, Windows substitutes a similar font.


Object Property

Overrides a standard property or method when a new control has a property or method of the same name.

Syntax

object.Object[.property |.method]

The Object property syntax has these parts:

Part | Description
object | Required. The name of an object you have added to the Microsoft Forms Toolbox.
property | Optional. A property that has the same name as a standard Microsoft Forms property.
method | Optional. A method that has the same name as a standard Microsoft Forms method.

Remarks

Object is read-only.

If you add a new control to the Microsoft Forms Toolbox, it is possible that the added control will have a property or method with the same name as a standard Microsoft Forms property or method. The Object property lets you use the property or method from the added control, rather than the standard property or method.


Orientation Property

Specifies whether the SpinButton or ScrollBar is oriented vertically or horizontally.

Syntax

object.Orientation [=Orientation]

The Orientation property syntax has these parts:

Part | Description
object | Required. A valid object.
Orientation | Optional. Orientation of the control.

Settings

The settings for Orientation are:

Value | Description
–1 | Automatically determines the orientation based upon the dimensions of the control (default).
0 | Control is rendered vertically.
1 | Control is rendered horizontally.

Remarks

If you specify automatic orientation, the height and width of the control determine whether it appears horizontally or vertically. For example, if the control is wider than it is tall, it appears horizontally; if it is taller than it is wide, the control appears vertically.


Parent Property

Returns the name of the form, object, or collection that contains a specific control, object, or collection.

Syntax

object.Parent

The Parent property syntax has these parts:

Part | Description
object | Required. A valid object.

Remarks

Parent is read-only.

Use the Parent property to access the properties, methods, or controls of an object's parent.

This property is useful in an application in which you pass objects as arguments. For example, you could pass a control variable to a general procedure in a module, and use Parent to access its parent form.


PasswordChar Property

Specifies whether placeholder characters are displayed instead of the characters actually entered in a TextBox.

Syntax

object.PasswordChar [= String]

The PasswordChar property syntax has these parts:

Part | Description
object | Required. A valid object.
String | Optional. A string expression specifying the placeholder character.

Remarks

You can use the PasswordChar property to protect sensitive information, such as passwords or security codes. The value of PasswordChar is the character (usually an asterisk) that appears in a control instead of the actual characters that the user types. If you don't specify a character, the control displays the characters that the user types.


Picture Property

Specifies the bitmap to display on an object.

Syntax

object.Picture = LoadPicture( pathname )

The Picture property syntax has these parts:

Part | Description
object | Required. A valid object.
pathname | Required. The full path to a picture file.

Remarks

You must use the control's property page to assign a bitmap to the Picture property. You cannot use the LoadPicture function to assign a bitmap to Picture.

To remove a picture that is assigned to a control, click the value of the Picture property in the property page and then press DELETE. Pressing BACKSPACE will not remove the picture.

Note For controls with captions, use the PicturePosition property to specify where to display the picture on the object. Use the PictureSizeMode property to determine how the picture fills the object.

Transparent pictures sometimes have a hazy appearance. If you do not like this appearance, display the picture on a control that supports opaque images. Image and MultiPage support opaque images.


PictureAlignment Property

Specifies the location of a background picture.

Syntax

object.PictureAlignment [=PictureAlignment]

The PictureAlignment property syntax has these parts:

Part | Description
object | Required. A valid object.
PictureAlignment | Optional. The position where the picture aligns with the control.

Settings

The settings for PictureAlignment are:

Value | Description
0 | The top left corner.
1 | The top right corner.
2 | The center.
3 | The bottom left corner.
4 | The bottom right corner.

Remarks

The PictureAlignment property identifies which corner of the picture is the same as the corresponding corner of the control or container where the picture is used.

For example, setting PictureAlignment to 0 means that the top left corner of the picture coincides with the top left corner of the control or container. Setting PictureAlignment to 2 positions the picture in the middle, relative to the height as well as the width of the control or container.

If you tile an image on a control or container, the setting of PictureAlignment affects the tiling pattern. For example, if PictureAlignment is set to 0, the first copy of the image is laid in the upper left corner of the control or container and additional copies are tiled from left to right across each row. If PictureAlignment is 2, the first copy of the image is laid at the center of the control or container, additional copies are laid to the left and right to complete the row, and additional rows are added to fill the control or container.

Note Setting the PictureSizeMode property to 2 overrides PictureAlignment. When PictureSizeMode is set to 2, the picture fills the entire control or container.


PicturePosition Property

Specifies the location of the picture relative to its caption.

Syntax

object.PicturePosition [=PicturePosition]

The PicturePosition property syntax has these parts:

Part | Description
object | Required. A valid object.
PicturePosition | Optional. How the picture aligns with its container.

Settings

The settings for PicturePosition are:

Value | Description
0 | The picture appears to the left of the caption. The caption is aligned with the top of the picture.
1 | The picture appears to the left of the caption. The caption is centered relative to the picture.
2 | The picture appears to the left of the caption. The caption is aligned with the bottom of the picture.
3 | The picture appears to the right of the caption. The caption is aligned with the top of the picture.
4 | The picture appears to the right of the caption. The caption is centered relative to the picture.
5 | The picture appears to the right of the caption. The caption is aligned with the bottom of the picture.
6 | The picture appears above the caption. The caption is aligned with the left edge of the picture.
7 | The picture appears above the caption. The caption is centered below the picture (default).
8 | The picture appears above the caption. The caption is aligned with the right edge of the picture.
9 | The picture appears below the caption. The caption is aligned with the left edge of the picture.
10 | The picture appears below the caption. The caption is centered above the picture.
11 | The picture appears below the caption. The caption is aligned with the right edge of the picture.
12 | The picture appears in the center of the control. The caption is centered horizontally and vertically on top of the picture.

Remarks

The picture and the caption, as a unit, are centered on the control. If no caption exists, the picture's location is relative to the center of the control.

This property is ignored if the Picture property does not specify a picture.


PictureSizeMode Property

Specifies how to display the background picture on a control, form, or page.

Syntax

object.PictureSizeMode [=PictureSizeMode]

The PictureSizeMode property syntax has these parts:

Part | Description
object | Required. A valid object.
PictureSizeMode | Optional. The action to take if the picture and the form or page that contains it are not the same size.

Settings

The settings for PictureSizeMode are:

Value | Description
0 | Crops any part of the picture that is larger than the form or page (default).
1 | Stretches the picture to fill the form or page. This setting distorts the picture in either the horizontal or vertical direction.
3 | Enlarges the picture, but does not distort the picture in either the horizontal or vertical direction.

Remarks

The PictureSizeModeClip setting indicates you want to show the picture in its original size and scale. If the form or page is smaller than the picture, this setting only shows the part of the picture that fits within the form or page.

The 1 and 3 settings both enlarge the image, but 1 causes distortion. The 1 setting enlarges the image horizontally and vertically until the image reaches the corresponding edges of the container or control. The 3 setting enlarges the image until it reaches either the horizontal or vertical edges of the container or control. If the image reaches the horizontal edges first, any remaining distance to the vertical edges remains blank. If it reaches the vertical edges first, any remaining distance to the horizontal edges remains blank.

Note Setting the PictureSizeMode property to 2 overrides PictureAlignment. When PictureSizeMode is set to 2, the picture fills the entire control or container.


PictureTiling Property

Lets you tile a picture in a form or page.

Syntax

object.PictureTiling [= Boolean]

The PictureTiling property syntax has these parts:

Part | Description
object | Required. A valid object.
Boolean | Optional. Whether a picture is repeated across a background.

Settings

The settings for Boolean are:

Value | Description
True | The picture is tiled across the background.
False | The picture is not tiled across the background (default).

Remarks

If a picture is smaller than the form or page that contains it, you can tile the picture on the form or page.

The tiling pattern depends on the current setting of the PictureAlignment and PictureSizeMode properties. For example, if PictureAlignment is set to 0, the tiling pattern starts at the upper left and repeats the picture across the form or page and down the height of the form or page. If PictureSizeMode is set to 0, the tiling pattern crops the last tile if it doesn't completely fit on the form or page.


ProportionalThumb Property

Specifies whether the size of the scroll box is proportional to the scrolling region or fixed.

Syntax

object.ProportionalThumb [= Boolean]

The ProportionalThumb property syntax has these parts:

Part | Description
object | Required. A valid object.
Boolean | Optional. Whether the scroll box is proportional or fixed.

Settings

The settings for Boolean are:

Value | Description
True | The scroll box is proportional in size to the scrolling region (default).
False | The scroll box is a fixed size.

Remarks

The size of a proportional scroll box graphically represents the percentage of the object that is visible in the window. For example, if 75 percent of an object is visible, the scroll box covers three-fourths of the scrolling region in the scroll bar.

If the scroll box is a fixed size, the system determines its size based on the height and width of the scroll bar.


RowSource Property

Specifies the source providing a list for a ComboBox or ListBox.

Syntax

object.RowSource [= String]

The RowSource property syntax has these parts:

Part | Description
object | Required. A valid object.
String | Optional. The source of the list for the ComboBox or ListBox.

Remarks

The RowSource property accepts worksheet ranges from Microsoft Excel.


ScrollBars Property

Specifies whether a control, form, or page has vertical scroll bars, horizontal scroll bars, or both.

Syntax

object.ScrollBars [=ScrollBars]

The ScrollBars property syntax has these parts:

Part | Description
object | Required. A valid object.
ScrollBars | Optional. Where scroll bars should be displayed.

Settings

The settings for ScrollBars are:

Value | Description
0 | Displays no scroll bars (default).
1 | Displays a horizontal scroll bar.
2 | Displays a vertical scroll bar.
3 | Displays both a horizontal and a vertical scroll bar.

Remarks

If the KeepScrollBarsVisible property is True, any scroll bar on a form or page is always visible, regardless of whether the object's contents fit within the object's borders.

If visible, a scroll bar constrains its scroll box to the visible region of the scroll bar. It also modifies the scroll position as needed to keep the entire scroll bar visible. The range of a scroll bar changes when the value of the ScrollBars property changes, the scroll size changes, or the visible size changes.

If a scroll bar is not visible, then you can set its scroll position to any value. Negative values and values greater than the scroll size are both valid.

For a single-line control, you can display a horizontal scroll bar by using the ScrollBars and AutoSize properties. Scroll bars are hidden or displayed according to the following rules:

  1. When ScrollBars is set to ScrollBarsNone, no scroll bar is displayed.
  2. When ScrollBars is set to 1 or 3, the control displays a horizontal scroll bar if the text is longer than the edit region and if the control has enough room to include the scroll bar underneath its edit region.
  3. When AutoSize is True, the control enlarges itself to accommodate the addition of a scroll bar unless the control is at or near its maximum size.

For a multiline TextBox, you can display scroll bars by using the ScrollBars, WordWrap, and AutoSize properties. Scroll bars are hidden or displayed according to the following rules:

  1. When ScrollBars is set to 0, no scroll bar is displayed.
  2. When ScrollBars is set to 2 or 3, the control displays a vertical scroll bar if the text is longer than the edit region and if the control has enough room to include the scroll bar at the right edge of its edit region.
  3. When WordWrap is True, the multiline control will not display a horizontal scroll bar. Most multiline controls do not use a horizontal scroll bar.
  4. A multiline control can display a horizontal scroll bar if the following conditions occur simultaneously:
    • The edit region contains a word that is longer than the edit region's width.
    • The control has enabled horizontal scroll bars.
    • The control has enough room to include the scroll bar under the edit region.
    • The WordWrap property is set to False.


ScrollHeight, ScrollWidth Properties

Specify the height, in points, of the total area that can be viewed by moving the scroll bars on the control, form, or page.

Syntax

object.ScrollHeight [= Single]

object.ScrollWidth [= Single]

The ScrollHeight and ScrollWidth property syntaxes have these parts:

Part | Description
object | Required. A valid object.
Single | Optional. The height or width of the scrollable region.


ScrollLeft, ScrollTop Properties

Specify the distance, in points, of the left or top edge of the visible form from the left or top edge of the logical form, page, or control.

Syntax

object.ScrollLeft [= Single]

object.ScrollTop [= Single]

The ScrollLeft and ScrollTop property syntaxes have these parts:

Part | Description
object | Required. A valid object.
Single | Optional. The distance from the edge of the form.

Remarks

The minimum value is zero; the maximum value is the difference between the value of the ScrollWidth property and the value of the Width property for the form or page.


Selected Property

Returns or sets the selection state of items in a ListBox.

Syntax

object.Selected( index ) [= Boolean]

The Selected property syntax has these parts:

Part | Description
object | Required. A valid object.
index | Required. An integer with a range from 0 to one less than the number of items in the list.
Boolean | Optional. Whether an item is selected.

Settings

The settings for Boolean are:

Value | Description
True | The item is selected.
False | The item is not selected.

Remarks

The Selected property is useful when users can make multiple selections. You can use this property to determine the selected rows in a multi-select list box. You can also use this property to select or deselect rows in a list from code.

The default value of this property is based on the current selection state of the ListBox.

For single-selection list boxes, the Value or ListIndex properties are recommended for getting and setting the selection. In this case, ListIndex returns the index of the selected item. However, in a multiple selection, ListIndex returns the index of the row contained within the focus rectangle, regardless of whether the row is actually selected.

When a list box control's MultiSelect property is set to None, only one row can have its Selected property set to True.

Entering a value that is out of range for the index does not generate an error message, but does not set a property for any item in the list.


SelectedItem Property

Returns the currently selected Tab or Page object.

Syntax

object.SelectedItem

The SelectedItem property syntax has these parts:

Part | Description
object | Required. A valid TabStrip or MultiPage.

Remarks

The SelectedItem property is read-only. Use SelectedItem to programmatically control the currently selected Tab or Page object. For example, you can use SelectedItem to assign values to properties of a Tab or Page object.


SelectionMargin Property

Specifies whether the user can select a line of text by clicking in the region to the left of the text.

Syntax

object.SelectionMargin [= Boolean]

The SelectionMargin property syntax has these parts:

Part | Description
object | Required. A valid object.
Boolean | Optional. Whether clicking in the margin selects a line of text.

Settings

The settings for Boolean are:

Value | Description
True | Clicking in margin causes selection of text (default).
False | Clicking in margin does not cause selection of text.

Remarks

When the SelectionMargin property is True, the selection margin occupies a thin strip along the left edge of a control's edit region. When set to False, the entire edit region can store text.

If the SelectionMargin property is set to True when a control is printed, the selection margin also prints.


SelLength Property

The number of characters selected in a TextBox or the text portion of a ComboBox.

Syntax

object.SelLength [= Long]

The SelLength property syntax has these parts:

Part | Description
object | Required. A valid object.
Long | Optional. A numeric expression specifying the number of characters selected. For SelLength and SelStart, the valid range of settings is 0 to the total number of characters in the edit area of a ComboBox or TextBox.

Remarks

The SelLength property is always valid, even when the control does not have focus. Setting SelLength to a value less than zero creates an error. Attempting to set SelLength to a value greater than the number of characters available in a control results in a value equal to the number of characters in the control.

Note Changing the value of the SelStart property cancels any existing selection in the control, places an insertion point in the text, and sets SelLength to zero.

The default value, zero, means that no text is currently selected.


SelStart Property

Indicates the starting point of selected text, or the insertion point if no text is selected.

Syntax

object.SelStart [= Long]

The SelStart property syntax has these parts:

Part | Description
object | Required. A valid object.
Long | Optional. A numeric expression specifying the starting point of text selected. For SelLength and SelStart, the valid range of settings is 0 to the total number of characters in the edit area of a ComboBox or TextBox. The default value is zero.

Remarks

The SelStart property is always valid, even when the control does not have focus. Setting SelStart to a value less than zero creates an error. Attempting to set SelStart to a value greater than the number of characters available in a control results in a value equal to the number of characters in the control.

Changing the value of SelStart cancels any existing selection in the control, places an insertion point in the text, and sets the SelLength property to zero.


SelText Property

Returns or sets the selected text of a control.

Syntax

object.SelText [= String]

The SelText property syntax has these parts:

Part | Description
object | Required. A valid object.
String | Optional. A string expression containing the selected text.

Remarks

If no characters are selected in the edit region of the control, the SelText property returns a zero length string. This property is valid regardless of whether the control has the focus.


ShowDropButtonWhen Property

Specifies when to show the drop-down button for a ComboBox.

Syntax

object.ShowDropButtonWhen [=ShowDropButtonWhen]

The ShowDropButtonWhen property syntax has these parts:

Part | Description
object | Required. A valid object.
ShowDropButtonWhen | Optional. The circumstances under which the drop-down button will be visible.

Settings

The settings for ShowDropButtonWhen are:

Value | Description
0 | Do not show the drop-down button under any circumstances.
1 | Show the drop-down button when the control has the focus.
2 | Always show the drop-down button.

For a ComboBox, the default value is 2.


SmallChange Property

Specifies the amount of movement that occurs when the user clicks either scroll arrow in a ScrollBar or SpinButton.

Syntax

object.SmallChange [= Long]

The SmallChange property syntax has these parts:

Part | Description
object | Required. A valid object.
Long | Optional. An integer that specifies the amount of change to the Value property.

Remarks

The SmallChange property does not have units.

Any integer is an acceptable setting for this property. The recommended range of values is from –32,767 to +32,767. The default value is 1.


SpecialEffect Property

Specifies the visual appearance of an object.

Syntax

object.SpecialEffect [=SpecialEffect]

The SpecialEffect property syntax has these parts:

Part | Description
object | Required. A valid object.
SpecialEffect | Optional. The desired visual appearance of an object other than a CheckBox, OptionButton, or ToggleButton.

Settings

The settings for SpecialEffect are:

Value | Description
0 | Object appears flat, distinguished from the surrounding form by a border, a change of color, or both. Default for Image and Label, valid for all controls.
1 | Object has a highlight on the top and left and a shadow on the bottom and right. Not valid for check boxes or option buttons.
2 | Object has a shadow on the top and left and a highlight on the bottom and right. The control and its border appear to be carved into the form that contains them. Default for CheckBox and OptionButton, valid for all controls (default).
3 | Border appears to be carved around the edge of the control. Not valid for check boxes or option buttons.
6 | Object has a ridge on the bottom and right and appears flat on the top and left. Not valid for check boxes or option buttons.

For a Frame, the default value is 2.

Note that only 0 and 2 are acceptable values for CheckBox, OptionButton, and ToggleButton. All values listed are acceptable for other controls.

Remarks

You can use either the SpecialEffect or the BorderStyle property to specify the edging for a control, but not both. If you specify a nonzero value for one of these properties, the system sets the value of the other property to zero. For example, if you set SpecialEffect to 1, the system sets BorderStyle to 0.

For a Frame, BorderStyle is ignored if SpecialEffect is 0.

SpecialEffect uses the system colors to define its borders.

Note Although the SpecialEffect property exists on the ToggleButton, the property is disabled. You cannot set or return a value for this property on the ToggleButton.


Style Property

For ComboBox, specifies how the user can choose or set the control's value. For MultiPage and TabStrip, identifies the style of the tabs on the control.

Syntax

object.Style [=Style]

The Style property syntax has these parts:

Part | Description
object | Required. A valid object.
Style | Optional. Specifies how a user sets the value of a ComboBox.

Settings

The settings for ComboBox are:

Value | Description
0 | The ComboBox behaves as a drop-down combo box. The user can type a value in the edit region or select a value from the drop-down list (default).
2 | The ComboBox behaves as a list box. The user must choose a value from the list.

The settings for MultiPage and TabStrip are::

Value | Description
0 | Displays tabs on the tab bar (default).
1 | Displays buttons on the tab bar.
2 | Does not display the tab bar.


TabFixedHeight, TabFixedWidth Properties

Sets or returns the fixed height or width of the tabs in points.

Syntax

object.TabFixedHeight [= Single]

object.TabFixedWidth [= Single]

The TabFixedHeight and TabFixedWidth property syntaxes have these parts:

Part | Description
object | Required. A valid object.
Single | Optional. The number of points of the height or width of the tabs on a TabStrip or MultiPage.

Settings

If the value is 0, tab widths are automatically adjusted so that each tab is wide enough to accommodate its contents and each row of tabs spans the width of the control.

If the value is greater than 0, all tabs have an identical width as specified by this property.

Remarks

The minimum size is 4 points.


TabIndex Property

Specifies the position of a single object in the form's tab order.

Syntax

object.TabIndex [= Integer]

The TabIndex property syntax has these parts:

Part | Description
object | Required. A valid object.
Integer | Optional. An integer from 0 to one less than the number of controls on the form that have a TabIndex property. Assigning a TabIndex value of less than 0 generates an error. If you assign a TabIndex value greater than the largest index value, the system resets the value to the maximum allowable value.

Remarks

The index value of the first object in the tab order is zero.


TabKeyBehavior Property

Determines whether tabs are allowed in the edit region.

Syntax

object.TabKeyBehavior [= Boolean]

The TabKeyBehavior property syntax has these parts:

Part | Description
object | Required. A valid object.
Boolean | Optional. The effect of pressing TAB.

Settings

The settings for Boolean are:

Value | Description
True | Pressing TAB inserts a tab character in the edit region.
False | Pressing TAB moves the focus to the next object in the tab order (default).

Remarks

The TabKeyBehavior and MultiLine properties are closely related. The values described above only apply if MultiLine is True. If MultiLine is False, pressing TAB always moves the focus to the next control in the tab order regardless of the value of TabKeyBehavior.

The effect of pressing CTRL+TAB also depends on the value of MultiLine. If MultiLine is True, pressing CTRL+TAB creates a new line regardless of the value of TabKeyBehavior. If MultiLine is False, pressing CTRL+TAB has no effect.


TabOrientation Property

Specifies the location of the tabs on a MultiPage or TabStrip.

Syntax

object.TabOrientation [=TabOrientation]

The TabOrientation property syntax has these parts:

Part | Description
object | Required. A valid object.
TabOrientation | Optional. Where the tabs will appear.

Settings

The settings for TabOrientation are:

Value | Description
0 | The tabs appear at the top of the control (default).
1 | The tabs appear at the bottom of the control.
2 | The tabs appear at the left side of the control.
3 | The tabs appear at the right side of the control.

Remarks

If you use TrueType fonts, the text rotates when the TabOrientation property is set to 2 or 3. If you use bitmapped fonts, the text does not rotate.


TabStop Property

Indicates whether an object can receive focus when the user tabs to it.

Syntax

object.TabStop [= Boolean]

The TabStop property syntax has these parts:

Part | Description
object | Required. A valid object.
Boolean | Optional. Whether the object is a tab stop.

Settings

The settings for Boolean are:

Value | Description
True | Designates the object as a tab stop (default).
False | Bypasses the object when the user is tabbing, although the object still holds its place in the actual tab order, as determined by the TabIndex property.

Remarks

You can combine the settings of the Enabled and the TabStop properties to prevent the user from selecting a command button with TAB, while still allowing the user to click the button. Setting TabStop to False means that the command button won't appear in the tab order. However, if Enabled is True, then the user can still click the command button, as long as TakeFocusOnClick is set to True.

When the user tabs into an enabled MultiPage or TabStrip, the first page or tab in the control receives the focus. If the first page or tab of a MultiPage or TabStrip is disabled, the first enabled page or tab of that control receives the focus. If all pages or tabs of a MultiPage or TabStrip are disabled, the control is disabled and cannot receive the focus.


Tag Property

Stores additional information about an object.

Syntax

object.Tag [= String]

The Tag property syntax has these parts:

Part | Description
object | Required. A valid object.
String | Optional. A string expression identifying the object. The default is a zero-length string ("").

Remarks

Use the Tag property to assign an identification string to an object without affecting other property settings or attributes.

For example, you can use Tag to check the identity of a form or control that is passed as a variable to a procedure.


TakeFocusOnClick Property

Specifies whether a control takes the focus when clicked.

Syntax

object.TakeFocusOnClick [= Boolean]

The TakeFocusOnClick property syntax has these parts:

Part | Description
object | Required. A valid object.
Boolean | Optional. Specifies whether a control takes the focus when clicked.

Settings

The settings for Boolean are:

Value | Description
True | The button takes the focus when clicked (default).
False | The button does not take the focus when clicked.

Remarks

The TakeFocusOnClick property defines only what happens when the user clicks a control. If the user tabs to the control, the control takes the focus regardless of the value of TakeFocusOnClick.

Use this property to complete actions that affect a control without requiring that control to give up focus. For example, assume your form includes a TextBox and a CommandButton that checks for correct spelling of text. You would like to be able to select text in the TextBox, then click the CommandButton and run the spelling checker without taking focus away from the TextBox. You can do this by setting the TakeFocusOnClick property of the CommandButton to False.


Text Property

Returns or sets the text in a TextBox. Changes the selected row in a ComboBox or ListBox.

Syntax

object.Text [= String]

The Text property syntax has these parts:

Part | Description
object | Required. A valid object.
String | Optional. A string expression specifying text. The default value is a zero-length string ("").

Remarks

For a TextBox, any value you assign to the Text property is also assigned to the Value property.

For a ComboBox, you can use Text to update the value of the control. If the value of Text matches an existing list entry, the value of the ListIndex property (the index of the current row) is set to the row that matches Text. If the value of Text does not match a row, ListIndex is set to –1.

For a ListBox, the value of Text must match an existing list entry. Specifying a value that does not match an existing list entry causes an error.

When the Text property of a ComboBox changes (such as when a user types an entry into the control), the new text is compared to the column of data specified by TextColumn.

You cannot use Text to change the value of an entry in a ComboBox or ListBox; use the Column or List property for this purpose.

The ForeColor property determines the color of the text.


TextAlign Property

Specifies how text is aligned in a control.

Syntax

object.TextAlign [=TextAlign]

The TextAlign property syntax has these parts:

Part | Description
object | Required. A valid object.
TextAlign | Optional. How text is aligned in the control.

Settings

The settings for TextAlign are:

Value | Description
1 | Aligns the first character of displayed text with the left edge of the control's display or edit area (default).
2 | Centers the text in the control's display or edit area.
3 | Aligns the last character of displayed text with the right edge of the control's display or edit area.

Remarks

For a ComboBox, the TextAlign property only affects the edit region; this property has no effect on the alignment of text in the list. For stand-alone labels, TextAlign determines the alignment of the label's caption.


TextColumn Property

Identifies the column in a ComboBox or ListBox to display to the user.

Syntax

object.TextColumn [= Variant]

The TextColumn property syntax has these parts:

Part | Description
object | Required. A valid object.
Variant | Optional. The column to be displayed.

Settings

Values for the TextColumn property range from –1 to the number of columns in the list. The TextColumn value for the first column is 1, the value of the second column is 2, and so on. Setting TextColumn to 0 displays the ListIndex values. Setting TextColumn to –1 displays the first column that has a ColumnWidths value greater than 0.

Remarks

When the user selects a row from a ComboBox or ListBox, the column referenced by TextColumn is stored in the Text property.For example, you could set up a multicolumn ListBox that contains the names of holidays in one column and dates for the holidays in a second column. To present the holiday names to users, specify the first column as the TextColumn. To store the dates of the holidays, specify the second column as the BoundColumn.

When the Text property of a ComboBox changes (such as when a user types an entry into the control), the new text is compared to the column of data specified by TextColumn.


TextLength Property

Returns the length, in characters, of text in the edit region of a TextBox or ComboBox.

Syntax

object.TextLength

The TextLength property syntax has these parts:

Part | Description
object | Required. A valid object.

Remarks

The TextLength property is read-only. For a multiline TextBox, TextLength includes LF (line feed) and CR (carriage return) characters.


TopIndex Property

Sets and returns the item that appears in the topmost position in the list.

Syntax

object.TopIndex [= Variant]

The TopIndex property syntax has these parts:

Part | Description
object | Required. A valid object.
Variant | Optional. The number of the list item that is displayed in the topmost position. The default is 0, or the first item in the list.

Settings

Returns the value –1 if the list is empty or not displayed.


TripleState Property

Determines whether a user can specify, from the user interface, the Null state for a CheckBox or ToggleButton.

Syntax

object.TripleState [= Boolean]

The TripleState property syntax has these parts:

Part | Description
object | Required. A valid object.
Boolean | Optional. Whether the control supports the Null state.

Settings

The settings for Boolean are:

Value | Description
True | The button clicks through three states.
False | The button only supports True and False (default).

Remarks

Although the TripleState property exists on the OptionButton, the property does not affect the action of the control. Regardless of the value of TripleState, you cannot set the control to Null through the user interface.

When the TripleState property is True, a user can choose from the values of Null, True, and False. The null value is displayed as a shaded button.

When TripleState is False, the user can choose either True or False.

A control set to Null does not initiate the Click event.

Regardless of the property setting, the Null value can always be assigned programmatically to an OptionButton, CheckBox or ToggleButton, causing that control to appear shaded.


Value Property

Specifies the state or content of a given control.

Syntax

object.Value [= Variant]

The Value property syntax has these parts:

Part | Description
object | Required. A valid object.
Variant | Optional. The state or content of the control.

Settings

Control | Description
CheckBox | An integer value indicating whether the item is selected:
 | Null Indicates the item is in a null state, neither selected nor cleared.
 | –1 True. Indicates the item is selected.
 | 0 False. Indicates the item is cleared.
OptionButton | Same as CheckBox.
ToggleButton | Same as CheckBox.
ScrollBar | An integer between the values specified for the Max and Min properties.
SpinButton | Same as ScrollBar.
ComboBox , ListBox | The value in the BoundColumn of the currently selected rows.
CommandButton | Always False.
MultiPage | An integer indicating the currently active page.
 | Zero (0) indicates the first page. The maximum value is one less than the number of pages.
TextBox | The text in the edit region.

Remarks

For a CommandButton, setting the Value property to True in a macro or procedure initiates the button's Click event.

For a ComboBox, changing the contents of Value does not change the value of BoundColumn. To add or delete entries in a ComboBox, you can use the AddItem or RemoveItem method.

For a TextBox, any value you assign to the Text property is also assigned to the Value property.

Value cannot be used with a multi-select ListBox.


VerticalScrollBarSide Property

Specifies whether a vertical scroll bar appears on the right or left side of a frame.

Syntax

object.VerticalScrollBarSide [= VerticalScrollBarSide]

The VerticalScrollBarSide property syntax has these parts:

Part | Description
object | Required. A valid object.
VerticalScrollBarSide | Optional. Where the scroll bar should appear.

Settings

Value | Description
0 | Puts the scroll bar on the right side (default).
1 | Puts the scroll bar on the left side.


Visible Property

Specifies whether an object is visible or hidden.

Syntax

object.Visible [= Boolean]

The Visible property syntax has these parts:

Part | Description
object | Required. A valid object.
Boolean | Optional. Whether the object is visible or hidden.

Settings

The settings for Boolean are:

Value | Description
True | Object is visible (default).
False | Object is hidden.

Remarks

Use the Visible property to control access to information without displaying it. For example, you could use the value of a control on a hidden form as the criteria for a query.

All controls are visible at design time.


WordWrap Property

Indicates whether the contents of a control automatically wrap at the end of a line.

Syntax

object.WordWrap [= Boolean]

The WordWrap property syntax has these parts:

Part | Description
object | Required. A valid object.
Boolean | Optional. Whether the control expands to fit the text.

Settings

The settings for Boolean are:

Value | Description
True | The text wraps (default).
False | The text does not wrap.

Remarks

For controls that support the MultiLine property as well as the WordWrap property, WordWrap is ignored when MultiLine is False.


Zoom Property

Specifies how much to change the size of a displayed object.

Syntax

object.Zoom [= Integer]

The Zoom property syntax has these parts:

Part | Description
object | Required. A valid object.
Integer | The percentage to increase or decrease the displayed image.

Remarks

The value of the Zoom property specifies a percentage of image enlargement or reduction by which an image display should change. Values from 10 to 400 are valid. The value specified is a percentage of the object’s original size; thus, a setting of 400 means you want to enlarge the image to four times its original size (or 400 percent), while a setting of 10 means you want to reduce the image to one-tenth of its original size (or 10 percent).


Step 2: Create an Outlook item in a public folder

  1. If the public folder, that you want to use does not exist, you can create it.

    How?

  2. In the Folder List or on the Outlook Bar, select the public folder in which you want to add the new item.
  3. On the File menu, point to New, and then click the item that you want to create.

Tip To quickly let others add the public folder to their Public Folders folder, you can send a shortcut in a mail message.

To go on to Step 3, click [image] .


Step 1: Create a public folder

To create a public folder, you must have permission to create folders in an existing public folder. For information about how to obtain permission, see your administrator.

  1. On the File menu, select New, and then click Folder. (CTRL+SHIFT+E)
  2. In the Name box, enter a name for the folder.
  3. In the Folder contains box, click the type of item that you want the folder to contain. A folder can only contain one type of item.
  4. Click the Select Folder button, and then click the public folder in which you want your new public folder to appear.
  5. If you do not want to add a Shortcut for the public folder to your Outlook Bar, click No in the Add shortcut to Outlook Bar? box.

Note You can copy a private folder to a public folder for quick creation of a public folder with existing items.

To go on to Step 2, click


Pages Collection

A Pages collection includes all the pages of a MultiPage.

Remarks

Each Pages collection provides the features to manage the number of pages in the collection and to identify the page that is currently in use.

The default value of the Pages collection identifies the current Page of a collection.

You can reference a Page by its index value. The index value reflects the ordinal position of the Page within the collection. The index of the first Page in a collection is 0; the index of the second Page is 1; and so on.


Tabs Collection

A Tabs collection includes all Tabs of a TabStrip.

Remarks

Each Tabs collection provides the features to manage the number of tabs in the collection and to identify the tab that is currently in use.

The default value of the Tabs collection identifies the current Tab of a collection.

You can reference a Tab by its index value. The index value reflects the ordinal position of the Tab within the collection. The index of the first Tab in a collection is 0; the index of the second Tab is 1; and so on.


Step 3: Create and use a custom view in a public folder

With custom views, you can arrange information in a public folder, exactly how you want it. You can set which view is initially shown when a user opens the public folder, and you can remove all the standard views from a public folder and only show the custom views you create. By setting the permission for a public folder, you can determine who has access to the folder.


Create an instant workgroup solution using public folders

By using custom views in a public folder, you can take an existing item, such as a contact, and turn it into a workgroup form from which any user of the public folder can get information or to which they can add data. With this method, you create an appointment, task, or contact in a public folder, create a custom view for the information in the folder, and then give permission to those who you want to use the folder.

Click a step below to begin:

Step 1: Create a public folder

Step 2: Create an Outlook item in a public folder

Step 3: Create and use a custom view in a public folder


Abs function example

The following example returns 53 for both functions.

ABS(-53)
ABS(53)


Accelerator, Caption Properties Example

This example changes the Accelerator and Caption properties of a CommandButton each time the user clicks the button by using the mouse or the accelerator key. The Click event contains the code to change the Accelerator and Caption properties.

To try this example, paste the code into the Script Editor of a form containing a CommandButton named CommandButton1. To run the code you need to open the form so the Open event will activate.

Dim CommandButton1

Sub Item_Open()
  Set CommandButton1 = Item.GetInspector.ModifiedFormPages("P.2").CommandButton1
  CommandButton1.Accelerator  = "C"         'Set Accelerator key to ALT + C
End Sub

Sub CommandButton1_Click ()
  If CommandButton1.Caption = "OK" Then     'Check caption, then change it.
    CommandButton1.Caption = "Clicked"
    CommandButton1.Accelerator  = "C"         'Set Accelerator key to ALT + C
  Else
    CommandButton1.Caption = "OK"
    CommandButton1.Accelerator  = "O"         'Set Accelerator key to ALT + O
  End If
End Sub


Accessing Controls Through the Controls Collection Example

The following example accesses individual controls from the Controls collection using a For Each...Next loop. When the user presses CommandButton1, the other controls are placed in a column along the left edge of the form using the Move method.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains a CommandButton named CommandButton1 and several other controls.

Dim CtrlHeight
Dim CtrlTop
Dim CtrlGap
Dim CommandButton1

Sub Item_Open()
  Set CommandButton1 = Item.GetInspector.ModifiedFormPages("P.2").CommandButton1

  CtrlHeight = 20
  CtrlGap = 5

  CommandButton1.Caption = "Click to move controls"
  CommandButton1.AutoSize = True
  CommandButton1.Left = 120
  CommandButton1.Top = CtrlTop
End Sub

Sub CommandButton1_Click()
  Dim MyControl

  Set AllControls = Item.GetInspector.ModifiedFormPages("P.2").Controls

  CtrlTop = 5

  For i = 0 to AllControls.Count - 1
    Set MyControl = AllControls(i)
    If MyControl.Name = "CommandButton1" Then
    'Don't move or resize this control.
    Else
      'Move method using unnamed arguments (left, top, width, height)
      MyControl.Move 5, CtrlTop, ,CtrlHeight

      'Calculate top coordinate for next control
      CtrlTop = CtrlTop + CtrlHeight + CtrlGap
    End If
  Next

End Sub


Accessing a Page Example

The following example accesses an individual page of a MultiPage in several ways:

  • Using the Pages collection with a numeric index.
  • Using the name of the individual page in the MultiPage.
  • Using the SelectedItem property.

To use this example, copy this sample code to the Script Editor of a form. Make sure that the form contains a MultiPage named MultiPage1 and a CommandButton named CommandButton1.

Sub CommandButton1_Click
  Dim PageName
  Set MultiPage1 = Item.GetInspector.ModifiedFormPages("P.2").MultiPage1

  For i = 0 To MultiPage1.Count - 1
    'Use index (numeric or string)
    MsgBox "MultiPage1.Pages(i).Caption = " & MultiPage1.Pages(i).Caption
    MsgBox "MultiPage1.Pages.Item(i).Caption = " & MultiPage1.Pages.Item(i).Caption

    'Use Page object without referring to Pages collection
    If i = 0 Then
      MsgBox "MultiPage1.Page1.Caption = " & MultiPage1.Page1.Caption
    ElseIf i = 1 Then
      MsgBox "MultiPage1.Page2.Caption = " & MultiPage1.Page2.Caption
    End If

    'Use SelectedItem Property
    MultiPage1.Value = i
    MsgBox "MultiPage1.SelectedItem.Caption = " & MultiPage1.SelectedItem.Caption
  Next
End Sub


Accessing a Tab Example

The following example accesses an individual tab of a TabStrip in several ways:

  • Using the Tabs collection with a numeric index.
  • Using the name of the individual Tab.
  • Using the SelectedItem property.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains a TabStrip named TabStrip1.

Sub Item_Open()
    Dim TabStrip1
    Dim TabName

     Set TabStrip1 = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls("TabStrip1")
    For i = 0 To TabStrip1.Count - 1
        'Using index (numeric or string)
        MsgBox "TabStrip1.Tabs(i).Caption = " & TabStrip1.Tabs(i).Caption
        MsgBox "TabStrip1.Tabs.Item(i).Caption = " & TabStrip1.Tabs.Item(i).Caption

        'Use Tab object without referring to Tabs collection
        If i = 0 Then
            MsgBox "TabStrip1.Tab1. Caption = " & TabStrip1.Tab1.Caption
        ElseIf i = 1 Then
            MsgBox "TabStrip1.Tab2. Caption = " & TabStrip1.Tab2.Caption
        End If

        'Use SelectedItem Property
        TabStrip1.Value = i
        MsgBox " TabStrip1.SelectedItem.Caption = " & TabStrip1.SelectedItem.Caption
    Next
End Sub


Adding a Control Example

The following example uses the Add method to add a control to a form at run time.

To use this example, copy this sample code to the Script Editor of a form. Make sure that the form contains:

  • A CommandButton named CommandButton1.
Dim Mycmd
Sub CommandButton1_Click()

   Set Mycmd = Item.GetInspector.ModifiedFormPages("P.2").Controls.Add("Forms.CommandButton.1") ', CommandButton2, Visible)
  Mycmd.Left = 18
  Mycmd.Top = 150
  Mycmd.Width = 175
  Mycmd.Height = 20
  Mycmd.Caption = "This is fun." & Mycmd.Name

End Sub


Adding a Control to a MultiPage Example

The following example uses the Add, Clear, and Remove methods to add and remove a control to a Page of a MultiPage at run time.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • A MultiPage named MultiPage1.
  • Three CommandButton controls named CommandButton1 through CommandButton3.
Dim MyTextBox
Dim MultiPage1

Sub Item_Open()
  Set MyPage = Item.GetInspector.ModifiedFormPages("P.2")
  Set MultiPage1 = MyPage.MultiPage1
  MyPage.CommandButton1.Caption = "Add control"
  MyPage.CommandButton2.Caption = "Clear controls"
  MyPage.CommandButton3.Caption = "Remove control"
End Sub

Sub CommandButton1_Click()
  Set MyTextBox = MultiPage1.Pages(0).Controls.Add("Forms.TextBox.1", "MyTextBox", 1)
End Sub

Sub CommandButton2_Click()
  MultiPage1.Pages(0).Controls.Clear
End Sub

Sub CommandButton3_Click()
  If MultiPage1.Pages(0).Controls.Count > 0  Then
    MultiPage1.Pages(0).Controls.Remove "MyTextBox"
  End If
End Sub


Alignment Property Example

The following example demonstrates the Alignment property used with several OptionButton controls. In this example, the user can change the alignment by clicking a ToggleButton.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains the following controls:

  • Two OptionButton controls named OptionButton1 and OptionButton2.
  • A ToggleButton named ToggleButton1.
Dim OptionButton1
Dim OptionButton2
Dim ToggleButton1

Sub Item_Open()
     Set OptionButton1 = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls("OptionButton1")
     Set OptionButton2 = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls("OptionButton2")
     Set ToggleButton1 = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls("ToggleButton1")

    OptionButton1.Alignment = 0 'fmAlignmentLeft
    OptionButton2.Alignment = 0 'fmAlignmentLeft

    OptionButton1.Caption = "Alignment with AutoSize"
    OptionButton2.Caption = "Choice 2"
    OptionButton1.AutoSize = True
    OptionButton2.AutoSize = True

    ToggleButton1.Caption = "Left Align"
    ToggleButton1.WordWrap = True
    ToggleButton1.Value = True
End Sub

Sub ToggleButton1_Click()
    If ToggleButton1.Value = True Then
        ToggleButton1.Caption = "Left Align"
        OptionButton1.Alignment = 0 'fmAlignmentLeft
        OptionButton2.Alignment = 0 'fmAlignmentLeft
    Else
        ToggleButton1.Caption = "Right Align"
        OptionButton1.Alignment = 1 'fmAlignmentRight
        OptionButton2.Alignment = 1 'fmAlignmentRight
    End If
End Sub


Asc function example

The following example returns the character code of the first letter in the Subject field.

Subject field | Function returns
International Sales | 73
Marketing Strategy | 77

ASC([Subject])


Atn function example

The following example uses the Atn function to return the value of pi.

ATN(1)*4


AutoSize Property Example

The following example demonstrates the effects of the AutoSize property with a single-line TextBox and a multiline TextBox. The user can enter text into either of the TextBox controls and turn AutoSize on or off independently of the contents of the TextBox. This code sample also uses the Text property.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • Two TextBox controls named TextBox1 and TextBox2.
  • A ToggleButton named ToggleButton1.
Dim ToggleButton1
Dim TextBox1
Dim TextBox2

Sub Item_Open()
  Set ToggleButton1 = Item.GetInspector.ModifiedFormPages("P.2").ToggleButton1
  Set TextBox1 = Item.GetInspector.ModifiedFormPages("P.2").TextBox1
  Set TextBox2 = Item.GetInspector.ModifiedFormPages("P.2").TextBox2

  TextBox1.Text = "Single-line TextBox. Type your text here."

  TextBox2.MultiLine = True
  TextBox2.Text = "Multi-line TextBox. Type your text here. Use SHIFT+ENTER to start a new line."

  ToggleButton1.Value = True
  ToggleButton1.Caption = "AutoSize On"
  TextBox1.AutoSize = True
  TextBox2.AutoSize = True
End Sub

Sub ToggleButton1_Click()
  If ToggleButton1.Value = True Then
    ToggleButton1.Caption = "AutoSize On"
    TextBox1.AutoSize = True
    TextBox2.AutoSize = True
  Else
    ToggleButton1.Caption = "AutoSize Off"
    TextBox1.AutoSize = False
    TextBox2.AutoSize = False
  End If
End Sub


Bold, Italic, Size, StrikeThrough, Underline, Weight Properties Example

The following example demonstrates a Font object and the Bold, Italic, Size, StrikeThrough, Underline, and Weight properties related to fonts. You can manipulate font properties of an object directly or by using an alias, as this example also shows.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • A Label named Label1.
  • Four ToggleButton controls named ToggleButton1 through ToggleButton4.
  • A second Label and a TextBox named Label2 and TextBox1.
Dim MyFont
Dim ToggleButton1
Dim ToggleButton2
Dim ToggleButton3
Dim ToggleButton4
Dim Label1
Dim Label2
Dim TextBox1

Sub Item_Open()
  Set MyPage = Item.GetInspector.ModifiedFormPages("P.2")
  Set ToggleButton1 = MyPage.ToggleButton1
  Set ToggleButton2 = MyPage.ToggleButton2
  Set ToggleButton3 = MyPage.ToggleButton3
  Set ToggleButton4 = MyPage.ToggleButton4
  Set Label1 = MyPage.Label1
  Set Label2 = MyPage.Label2
  Set TextBox1 = MyPage.TextBox1
  Set MyFont = Label1.Font

  ToggleButton1.Value = True
  ToggleButton1.Caption = "Bold On"

  Label1.AutoSize = True        'Set size of Label1
  Label1.AutoSize = False

  ToggleButton2.Value = False
  ToggleButton2.Caption = "Italic Off"

  ToggleButton3.Value = False
  ToggleButton3.Caption = "StrikeThrough Off"

  ToggleButton4.Value = False
  ToggleButton4.Caption = "Underline Off"

  Label2.Caption = "Font Weight"
  TextBox1.Text = Label1.Font.Weight
  TextBox1.Enabled = False

End Sub

Sub ToggleButton1_Click()
  If ToggleButton1.Value = True Then
    MyFont.Bold = True            'Using MyFont alias to control font
    ToggleButton1.Caption = "Bold On"
    MyFont.Size = 22              'Increase the font size
  Else
    MyFont.Bold = False
    ToggleButton1.Caption = "Bold Off"
    MyFont.Size = 8               'Return font size to initial size
  End If

  TextBox1.Text = CStr(MyFont.Weight)  'Bold and Weight are related
End Sub

Sub ToggleButton2_Click()
  If ToggleButton2.Value = True Then
    Label1.Font.Italic = True            'Using Label1.Font directly
    ToggleButton2.Caption = "Italic On"
  Else
    Label1.Font.Italic = False
    ToggleButton2.Caption = "Italic Off"
  End If
End Sub

Sub ToggleButton3_Click()
  If ToggleButton3.Value = True Then
    Label1.Font.Strikethrough = True            'Using Label1.Font directly
    ToggleButton3.Caption = "StrikeThrough On"
  Else
    Label1.Font.Strikethrough = False
    ToggleButton3.Caption = "StrikeThrough Off"
  End If
End Sub

Sub ToggleButton4_Click()
  If ToggleButton4.Value = True Then
    MyFont.Underline = True            'Using MyFont alias for Label1.Font
    ToggleButton4.Caption = "Underline On"
  Else
    Label1.Font.Underline = False
    ToggleButton4.Caption = "Underline Off"
  End If
End Sub


Border, Color Enhancements Example

The following example demonstrates the BorderStyle and SpecialEffect properties, showing each border available through these properties. The example also demonstrates how to control color settings by using the BackColor, BackStyle, BorderColor, and ForeColor properties.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • Six TextBox controls named TextBox1 through TextBox6.
  • Two ToggleButton controls named ToggleButton1 and ToggleButton2.
Dim TextBox1
Dim TextBox2
Dim TextBox3
Dim TextBox4
Dim TextBox5
Dim TextBox6
Dim ToggleButton1
Dim ToggleButton2

Sub Item_Open()
Set TextBox1 = Item.GetInspector.ModifiedFormPages("P.2").TextBox1
Set TextBox2 = Item.GetInspector.ModifiedFormPages("P.2").TextBox2
Set TextBox3 = Item.GetInspector.ModifiedFormPages("P.2").TextBox3
Set TextBox4 = Item.GetInspector.ModifiedFormPages("P.2").TextBox4
Set TextBox5 = Item.GetInspector.ModifiedFormPages("P.2").TextBox5
Set TextBox6 = Item.GetInspector.ModifiedFormPages("P.2").TextBox6
Set ToggleButton1 = Item.GetInspector.ModifiedFormPages("P.2").ToggleButton1
Set ToggleButton2 = Item.GetInspector.ModifiedFormPages("P.2").ToggleButton2
'Initialize each TextBox with a border style or special effect,
'and foreground and background colors

'TextBox1 initially uses a borderstyle
TextBox1.Text = "BorderStyle-Single"
TextBox1.BorderStyle = 1
TextBox1.BorderColor = RGB(255, 128, 128)   'Color - Salmon
TextBox1.ForeColor = RGB(255, 255, 0)       'Color - Yellow
TextBox1.BackColor = RGB(0, 128, 64)        'Color - Green #2

'TextBoxes 2 through 6 initially use special effects
TextBox2.Text = "Flat"
TextBox2.SpecialEffect = 0
TextBox2.ForeColor = RGB(64, 0, 0)          'Color - Brown
TextBox2.BackColor = RGB(0, 0, 255)         'Color - Blue

'Ensure the background style for TextBox2 is initially opaque.
TextBox2.BackStyle = 1

TextBox3.Text = "Etched"
TextBox3.SpecialEffect = 3
TextBox3.ForeColor = RGB(128, 0, 255)       'Color - Purple
TextBox3.BackColor = RGB(0, 255, 255)       'Color - Cyan

'Define BorderColor for later use (when borderstyle=fmBorderStyleSingle)
TextBox3.BorderColor = RGB(0, 0, 0)         'Color - Black

TextBox4.Text = "Bump"
TextBox4.SpecialEffect = 6
TextBox4.ForeColor = RGB(255, 0, 255)       'Color - Magenta
TextBox4.BackColor = RGB(0, 0, 100)         'Color - Navy blue

TextBox5.Text = "Raised"
TextBox5.SpecialEffect = 1
TextBox5.ForeColor = RGB(255, 0, 0)         'Color - Red
TextBox5.BackColor = RGB(128, 128, 128)     'Color - Gray

TextBox6.Text = "Sunken"
TextBox6.SpecialEffect = 2
TextBox6.ForeColor = RGB(0, 64, 0)          'Color - Olive
TextBox6.BackColor = RGB(0, 255, 0)         'Color - Green #1

ToggleButton1.Caption = "Swap styles"
ToggleButton2.Caption = "Transparent/Opaque background"
End Sub

Sub ToggleButton1_Click()

'Swap borders between TextBox1 and TextBox3
If ToggleButton1.Value = True Then
    'Change TextBox1 from BorderStyle to Etched
    TextBox1.Text = "Etched"
    TextBox1.SpecialEffect = 3

    'Change TextBox3 from Etched to BorderStyle
    TextBox3.Text = "BorderStyle-Single"
    TextBox3.BorderStyle = 1
Else
    'Change TextBox1 back to BorderStyle
    TextBox1.Text = "BorderStyle-Single"
    TextBox1.BorderStyle = 1

    'Change TextBox3 back to Etched
    TextBox3.Text = "Etched"
    TextBox3.SpecialEffect = 3
End If
End Sub

Sub ToggleButton2_Click()

'Set background to Opaque or Transparent
If ToggleButton2.Value = True Then
    'Change TextBox2 to a transparent background
    TextBox2.BackStyle = 0
Else
    'Change TextBox2 back to opaque background
    TextBox2.BackStyle = 1
End If

End Sub


BoundColumn Property Example

The following example demonstrates how the BoundColumn property influences the value of a ListBox. The user can choose to set the value of the ListBox to the index value of the specified row, or to a specified column of data in the ListBox.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • A ListBox named ListBox1.
  • A Label named Label1.
  • Three OptionButton controls named OptionButton1, OptionButton2, and OptionButton3.
Dim Listbox1
Dim OptionButton1
Dim OptionButton2
Dim OptionButton3
Dim Label1

Sub Item_Open
  Set Listbox1 = Item.GetInspector.ModifiedFormPages("P.2").Listbox1
  Set OptionButton1 = Item.GetInspector.ModifiedFormPages("P.2").OptionButton1
  Set OptionButton2 = Item.GetInspector.ModifiedFormPages("P.2").OptionButton2
  Set OptionButton3 = Item.GetInspector.ModifiedFormPages("P.2").OptionButton3
  Set Label1 = Item.GetInspector.ModifiedFormPages("P.2").Label1

  Listbox1.ColumnCount = 2
  Listbox1.AddItem "Item 1, Column 1"
  Listbox1.List(0, 1) = "Item 1, Column 2"
  Listbox1.AddItem "Item 2, Column 1"
  Listbox1.List(1, 1) = "Item 2, Column 2"
  Listbox1.Value  = "Item 1, Column 1"
  OptionButton1.Caption = "List Index"
  OptionButton2.Caption = "Column 1"
  OptionButton3.Caption = "Column 2"
  OptionButton2.Value = True
End Sub

Sub OptionButton1_Click
  Listbox1.BoundColumn = 0
  Label1.Caption = Listbox1.Value
End Sub

Sub OptionButton2_Click
  Listbox1.BoundColumn = 1
  Label1.Caption = Listbox1.Value
End Sub

Sub OptionButton3_Click
  Listbox1.BoundColumn = 2
  Label1.Caption = Listbox1.Value
End Sub

Sub Listbox1_Click
  Label1.Caption = Listbox1.Value
End Sub


UndoAction, RedoAction Methods Example

The following example demonstrates how to undo or redo text editing within a text box or within the text area of a ComboBox. This sample checks whether an undo or redo operation can occur and then performs the appropriate action. The sample uses the CanUndo and CanRedo properties, and the UndoAction and RedoAction methods.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • A TextBox named TextBox1.
  • A ComboBox named ComboBox1.
  • Two CommandButton controls named CommandButton1 and CommandButton2.
Dim UserForm1

Sub CommandButton1_Click()
    If UserForm1.CanUndo = True Then
        UserForm1.UndoAction
        MsgBox "Undid IT"
    Else
        MsgBox "No undo performed."
    End If
End Sub

Sub CommandButton2_Click()
    If UserForm1.CanRedo = True Then
        UserForm1.RedoAction
        MsgBox "Redid IT"
    Else
        MsgBox "No redo performed."
    End If
End Sub

Sub Item_Open()
     Set UserForm1 = Item.GetInspector.ModifiedFormPages("P.2")
     Set TextBox1 = UserForm1.Controls("TextBox1")
     Set ComboBox1 = UserForm1.Controls("ComboBox1")
     Set CommandButton1 = UserForm1.Controls("CommandButton1")
     Set CommandButton2 = UserForm1.Controls("CommandButton2")

    TextBox1.Text = "Type your text here."

    ComboBox1.ColumnCount = 3
    ComboBox1.AddItem "Choice 1, column 1"
    ComboBox1.List(0, 1) = "Choice 1, column 2"
    ComboBox1.List(0, 2) = "Choice 1, column 3"

    CommandButton1.Caption = "Undo"
    CommandButton2.Caption = "Redo"
End Sub


Choose function example

The following examples use the Choose function to display custom values for the value of the Importance field.

Importance field | Function returns
0 | Ignore
1 | Read Today
2 | Read Yesterday

Choose([Importance]+1, "Ignore", "Read Today", "Read Yesterday")


Chr function example

The example returns the character for the following character codes in the CharCode field.

CharCode field | Function returns
65 | A
97 | a
62 | >
37 | %

Chr([CharCode])


ClientHeight, ClientLeft, ClientTop, ClientWidth Properties Example

The following example sets the dimensions of an Image to the size of a TabStrip's client area when the user clicks a CommandButton. This code sample uses the following properties: Height, Left, Top, Width, ClientHeight, ClientLeft, ClientTop, and ClientWidth.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • A CommandButton named CommandButton1.
  • A TabStrip named TabStrip1.
  • An Image named Image1.
Dim CommandButton1
Dim Image1
Dim TabStrip1

Sub Item_Open
  Set CommandButton1 = Item.GetInspector.ModifiedFormPages("P.2").CommandButton1
  Set Image1 = Item.GetInspector.ModifiedFormPages("P.2").Image1
  Set TabStrip1 = Item.GetInspector.ModifiedFormPages("P.2").TabStrip1

  CommandButton1.Caption = "Size Image to Tab Area"
  CommandButton1.WordWrap = True
  CommandButton1.AutoSize = True
End Sub

Sub CommandButton1_Click
  Image1.ZOrder (fmFront) 'Place Image in front of TabStrip

'Client Left and ClientTop are measured from the edge of the TabStrip,
'not from the edges of the form containing the TabStrip.
  Image1.Left = TabStrip1.Left + TabStrip1.ClientTop
  Image1.Top = TabStrip1.Top + TabStrip1.ClientTop
  Image1.Width = TabStrip1.ClientWidth
  Image1.Height = TabStrip1.ClientHeight
End Sub


Column Property Example

The following example loads a two-dimensional array with data and, in turn, loads two ListBox controls using the Column and List properties. Note that the Column property transposes the array elements during loading.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains two ListBox controls named ListBox1 and ListBox2.

Dim MyArray(6,3)

Sub Item_Open()
    Dim i

    Set ListBox1 = Item.GetInspector.ModifiedFormPages("P.2").ListBox1
    Set ListBox2 = Item.GetInspector.ModifiedFormPages("P.2").ListBox2

    ListBox1.ColumnCount = 3        'The 1st list box contains 3 data columns
    ListBox2.ColumnCount = 6        'The 2nd box contains 6 data columns

    'Load integer values into first column of MyArray
    For i = 0 To 5
        MyArray(i, 0) = i
    Next

    'Load columns 2 and three of MyArray
    MyArray(0, 1) = "Zero"
    MyArray(1, 1) = "One"
    MyArray(2, 1) = "Two"
    MyArray(3, 1) = "Three"
    MyArray(4, 1) = "Four"
    MyArray(5, 1) = "Five"

    MyArray(0, 2) = "Zero"
    MyArray(1, 2) = "Un ou Une"
    MyArray(2, 2) = "Deux"
    MyArray(3, 2) = "Trois"
    MyArray(4, 2) = "Quatre"
    MyArray(5, 2) = "Cinq"

    'Load data into ListBox1 and ListBox2
    ListBox1.List() = MyArray
    ListBox2.Column() = MyArray

End Sub


ColumnWidths Property Example

The following example uses the ColumnWidths property to change the column widths of a multicolumn ListBox. The example uses three TextBox controls to specify the individual column widths and uses the Exit event to specify the units of measure of each TextBox.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • A ListBox named ListBox1.
  • Three custom text fields named Text1, Text2, and Text3.
  • Three TextBox controls named TextBox1, TextBox2, and TextBox3 that are bound to the custom text fields above.
  • A CommandButton named CommandButton1.

Try entering the value 0 to hide a column.

Dim MyArray(2, 3)
Dim ListBox1
Dim TextBox1
Dim TextBox2
Dim TextBox3
Dim CommandButton1

Sub Item_Open()
Dim i, j, Rows

Set ListBox1 = Item.GetInspector.ModifiedFormPages("P.2").ListBox1
Set TextBox1 = Item.GetInspector.ModifiedFormPages("P.2").TextBox1
Set TextBox2 = Item.GetInspector.ModifiedFormPages("P.2").TextBox2
Set TextBox3 = Item.GetInspector.ModifiedFormPages("P.2").TextBox3
Set CommandButton1 = Item.GetInspector.ModifiedFormPages("P.2").CommandButton1

ListBox1.ColumnCount = 3
Rows = 2

For j = 0 To ListBox1.ColumnCount - 1
    For i = 0 To Rows - 1
        MyArray(i, j) = "Row " & i & ", Column " & j
    Next
Next

ListBox1.List() = MyArray           'Load MyArray into ListBox1

TextBox1.Text = "1 in"              '1-inch columns initially
TextBox2.Text = "1 in"
TextBox3.Text = "1 in"

End Sub

Sub CommandButton1_Click()
    'ColumnWidths requires a value for each column separated by semicolons
    ListBox1.ColumnWidths = TextBox1.Text & ";" & TextBox2.Text & ";" & TextBox3.Text
End Sub

Sub Item_CustomPropertyChange(ByVal Name)
msgbox Name
Select Case Name
Case "Text1"
  'ColumnWidths accepts points (no units), inches or centimeters; make inches the default
    If Not (InStr(TextBox1.Text, "in") > 0 Or InStr(TextBox1.Text, "cm") > 0) Then
        TextBox1.Text = TextBox1.Text & " in"
    End If
Case "Text2"
    'ColumnWidths accepts points (no units), inches or centimeters; make inches the default
    If Not (InStr(TextBox2.Text, "in") > 0 Or InStr(TextBox2.Text, "cm") > 0) Then
        TextBox2.Text = TextBox2.Text & " in"
    End If
Case "Text3"
    'ColumnWidths accepts points (no units), inches or centimeters; make inches the default
    If Not (InStr(TextBox3.Text, "in") > 0 Or InStr(TextBox3.Text, "cm") > 0) Then
        TextBox3.Text = TextBox3.Text & " in"
    End If
End Select
End Sub


ControlTipText Property Example

The following example defines the ControlTipText property for three CommandButton controls and two Page objects in a MultiPage.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • A MultiPage named MultiPage1.
  • Three CommandButton controls named CommandButton1 through CommandButton3.

Note For an individual Page of a MultiPage, ControlTipText becomes enabled when the MultiPage or a control on the current page of the MultiPage has the focus.

Sub Item_Open()
  Set MultiPage1 = Item.GetInspector.ModifiedFormPages("P.2").MultiPage1
  Set CommandButton1 = Item.GetInspector.ModifiedFormPages("P.2").CommandButton1
  Set CommandButton2 = Item.GetInspector.ModifiedFormPages("P.2").CommandButton2
  Set CommandButton3 = Item.GetInspector.ModifiedFormPages("P.2").CommandButton3

  MultiPage1.Page1.ControlTipText = "Here in page 1"
  MultiPage1.Page2.ControlTipText = "Now in page 2"

  CommandButton1.ControlTipText = "And now here's"
  CommandButton2.ControlTipText = "a tip from"
  CommandButton3.ControlTipText = "your controls!"
End Sub


Cos function example

The following example uses the Cos function to return the cosine of the Angle field.

Cos([Angle])


Count Property Example

The following example displays the Count property of the Controls collection for the form, and the Count property identifying the number of pages and tabs of each MultiPage and TabStrip.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. The form can contain any number of controls, with the following restrictions:

  • Names of MultiPage controls must start with "MultiPage".
  • Names of TabStrip controls must start with "TabStrip".

Note You can add pages to a MultiPage or add tabs to a TabStrip while in design mode. Double-click on the control, then right click in the tab area of the control and choose New Page from the shortcut menu.

Sub Item_Open
    Dim Controls
    Dim MyControl

    Set Controls = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls
    MsgBox "Controls.Count = " & Controls.Count
    For i = 0 to Controls.Count -1
        Set MyControl = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls.Item(i)
        If (MyControl.Name = "MultiPage1") Then
            MsgBox MyControl.Name & ".Pages.Count = " & MyControl.Pages.Count
        ElseIf (MyControl.Name = "TabStrip1") Then
            MsgBox MyControl.Name & ".Tabs.Count = " & MyControl.Tabs.Count
        End If
    Next
End Sub


Cut and Paste From a Page Example

The following example uses the Add, Cut, and Paste methods to cut and paste a control from a Page of a MultiPage. The control involved in the cut and paste operations is dynamically added to the form.

This example assumes the user will add, then cut, then paste the new control.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • Three CommandButton controls named CommandButton1 through CommandButton3.
  • A MultiPage named MultiPage1.
Dim CommandButton1
Dim CommandButton2
Dim CommandButton3
Dim MultiPage1
Dim MyTextBox

Sub CommandButton1_Click()
    Set MyTextBox = MultiPage1.Pages(MultiPage1.Value).Controls.Add("Forms.TextBox.1", "MyTextBox", 1)
    CommandButton2.Enabled = True
    CommandButton1.Enabled = False
End Sub

Sub CommandButton2_Click()
    MultiPage1.Pages(MultiPage1.Value).Controls.Cut
    CommandButton3.Enabled = True
    CommandButton2.Enabled = False
End Sub

Sub CommandButton3_Click()
    Dim MyPage
    Set MyPage = MultiPage1.Pages.Item(MultiPage1.Value)

    MyPage.Paste
    CommandButton3.Enabled = False
End Sub

Sub Item_Open()
    Set CommandButton1 = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls("CommandButton1")
    Set CommandButton2 = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls("CommandButton2")
    Set CommandButton3 = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls("CommandButton3")
    Set MultiPage1 = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls("MultiPage1")

    CommandButton1.Caption = "Add"
    CommandButton2.Caption = "Cut"
    CommandButton3.Caption = "Paste"

    CommandButton1.Enabled = True
    CommandButton2.Enabled = False
    CommandButton3.Enabled = False
End Sub


Cut and Paste From a TextBox Example

The following example uses the Cut and Paste methods to cut text from one TextBox and paste it into another TextBox.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • Two TextBox controls named TextBox1 and TextBox2.
  • A CommandButton named CommandButton1.
Dim TextBox1
Dim TextBox2
Dim CommandButton1

Sub Item_Open()
    Set TextBox1 = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls("TextBox1")
    Set TextBox2 = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls("TextBox2")
    Set CommandButton1 = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls("CommandButton1")

    TextBox1.Text = "From TextBox1!"
    TextBox2.Text = "Hello "

    CommandButton1.Caption = "Cut and Paste"
    CommandButton1.AutoSize = True
End Sub

Sub CommandButton1_Click()
    TextBox2.SelStart = 0
    TextBox2.SelLength = TextBox2.TextLength
    TextBox2.Cut

    TextBox1.SetFocus
    TextBox1.SelStart = 0

    TextBox1.Paste
    TextBox2.SelStart = 0
End Sub


Cycle Property Example

The following example defines the Cycle property for a Frame and two Page objects in a MultiPage.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • A Frame named Frame1.
  • A MultiPage named MultiPage1 that contains two objects named Page1 and Page2.
  • Two CommandButton controls named CommandButton1 and CommandButton2.

In the form, the Frame, and each Page of the MultiPage, place a couple of controls, so you can see how Cycle affects the tab order of the Frame and MultiPage.

The user should tab through the controls to observe how Cycle affects the tab order. Pressing CommandButton1 extends the tab order to include controls in the Frame and Page objects. Pressing CommandButton2 restricts the tab order.

Dim Frame1
Dim MultiPage1

Sub Item_Open()
  Set Frame1 = Item.GetInspector.ModifiedFormPages("P.2").Frame1
  Set MultiPage1 = Item.GetInspector.ModifiedFormPages("P.2").MultiPage1
  RestrictCycles
End Sub

Sub RestrictCycles()
  'Limit tab order for the Frame and Page objects
  Frame1.Cycle = 2
  MultiPage1.Page1.Cycle = 2
  MultiPage1.Page2.Cycle = 2
End Sub
Sub CommandButton1_Click()
  'Extend tab order subforms (the Frame and Page objects)
  Frame1.Cycle = 0
  MultiPage1.Page1.Cycle = 0
  MultiPage1.Page2.Cycle = 0
End Sub

Sub CommandButton2_Click()
  RestrictCycles
End Sub


DateAdd function example

The following example takes the date of the Received field and, by using the DateAdd function, displays a corresponding date one month in the future.

DateAdd("m", 1, [Received])


DateDiff function example

The following example uses the DateDiff function to display the number of days between the date in the Received field and the current system date.

DateDiff("d", Now(), [Received])


Date function example

The following example uses the Date function to return the current system date.

Date( )


DatePart function example

The following example takes the date Received field and, by using the DatePart function, displays the quarter of the year it falls in.

DatePart("q", [Received])


DateSerial function example

The following example uses the DateSerial function to return the date for the specified year, month, and day.

DateSerial(1969, 2, 12)


DateValue function example

The following example uses the DateValue function to convert a string to a date.

DateValue("February 12, 1969")


Day function example

The following example uses the Day function to return the day of the Received field.

Day([Received])


DDB function example

By using the double-declining balance method, this example uses the DDB function to return the depreciation of an asset for a specified period given the initial cost (InitCost), the salvage value at the end of the asset's useful life (SalvageVal), the total life of the asset in years (LifeTime), and the period for which the depreciation is calculated (Depr), also in years.

DDB([InitCost], [SalvageVal], [LifeTime], [Depr])


DragBehavior, EnterFieldBehavior Properties Example

The following example uses the DragBehavior and EnterFieldBehavior properties to demonstrate the different effects that you can provide when entering a control and when dragging information from one control to another.

The sample uses two TextBox controls. You can set DragBehavior and EnterFieldBehavior for each control and see the effects of dragging from one control to another.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • A TextBox named TextBox1.
  • Two ToggleButton controls named ToggleButton1 and ToggleButton2. These controls are associated with TextBox1.
  • A TextBox named TextBox2.
  • Two ToggleButton controls named ToggleButton3 and ToggleButton4. These controls are associated with TextBox2.
Dim TextBox1, TextBox2
Dim ToggleButton1, ToggleButton2, ToggleButton3, ToggleButton4

Sub Item_Open()
     set TextBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TextBox1")
     set TextBox2 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TextBox2")
     set ToggleButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ToggleButton1")
     set ToggleButton2 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ToggleButton2")
     set ToggleButton3 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ToggleButton3")
     set ToggleButton4 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ToggleButton4")

    TextBox1.Text = "Once upon a time in a land ...,"
    ToggleButton1.Value = True
    ToggleButton1.Caption = "Drag Enabled"
    ToggleButton1.WordWrap = True
    TextBox1.DragBehavior = 1 'fmDragBehaviorEnabled

    ToggleButton2.Value = True
    ToggleButton2.Caption = "Recall Selection"
    ToggleButton2.WordWrap = True
    TextBox1.EnterFieldBehavior = 1 'fmEnterFieldBehaviorRecallSelection

    TextBox2.Text = "XXX, YYYY"
    ToggleButton3.Value = False
    ToggleButton3.Caption = "Drag Disabled"
    ToggleButton3.WordWrap = True
    TextBox2.DragBehavior = 0 'fmDragBehaviorDisabled

    ToggleButton4.Value = False
    ToggleButton4.Caption = "Select All"
    ToggleButton4.WordWrap = True
    TextBox2.EnterFieldBehavior = 0 'fmEnterFieldBehaviorSelectAll
End Sub

Sub ToggleButton1_Click()
    If ToggleButton1.Value = True Then
       ToggleButton1.Caption = "Drag Enabled"
       TextBox1.DragBehavior = 1 'fmDragBehaviorEnabled
    Else
       ToggleButton1.Caption = "Drag Disabled"
       TextBox1.DragBehavior = 0 'fmDragBehaviorDisabled
    End If
End Sub

Sub ToggleButton2_Click()
    If ToggleButton2.Value = True Then
        ToggleButton2.Caption = "Recall Selection"
        TextBox1.EnterFieldBehavior = 1 'fmEnterFieldBehaviorRecallSelection
    Else
        ToggleButton2.Caption = "Select All"
        TextBox1.EnterFieldBehavior = 0 'fmEnterFieldBehaviorSelectAll
    End If
End Sub

Sub ToggleButton3_Click()
    If ToggleButton3.Value = True Then
       ToggleButton3.Caption = "Drag Enabled"
       TextBox2.DragBehavior = 1 'fmDragBehaviorEnabled
    Else
       ToggleButton3.Caption = "Drag Disabled"
       TextBox2.DragBehavior = 0 'fmDragBehaviorDisabled
    End If
End Sub

Sub ToggleButton4_Click()
    If ToggleButton4.Value = True Then
        ToggleButton4.Caption = "Recall Selection"
        TextBox2.EnterFieldBehavior = 1 'fmEnterFieldBehaviorRecallSelection
    Else
       ToggleButton4.Caption = "Select All"
       TextBox2.EnterFieldBehavior = 0 'fmEnterFieldBehaviorSelectAll
    End If
End Sub


DropButtonStyle, ShowDropButtonWhen Properties Example

The following example demonstrates the different symbols that you can specify for a drop-down arrow in a ComboBox or TextBox. In this example, the user chooses a drop-down arrow style from a ComboBox. This example also uses the Locked property. To use this example, copy this sample code to the Script Editor of a form. Make sure that the form contains:

  • A ComboBox named ComboBox1.
  • A Label named Label1.
  • A TextBox named TextBox1 placed beneath Label1.
Dim TextBox1
Dim ComboBox1
Dim Label1

Sub ComboBox1_Click()
    ComboBox1.DropButtonStyle = ComboBox1.Value
    TextBox1.DropButtonStyle = ComboBox1.Value
End Sub

Sub Item_Open()
     Set TextBox1 = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls("TextBox1")
     Set ComboBox1 = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls("ComboBox1")
     Set Label1 = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls("Label1")

    ComboBox1.ColumnCount = 2
    ComboBox1.BoundColumn = 2
    ComboBox1.TextColumn = 1

    ComboBox1.AddItem "Blank Button"
    ComboBox1.List(0, 1) = 0
    ComboBox1.AddItem "Down Arrow"
    ComboBox1.List(1, 1) = 1
    ComboBox1.AddItem "Ellipsis"
    ComboBox1.List(2, 1) = 2
    ComboBox1.AddItem "Underscore"
    ComboBox1.List(3, 1) = 3

    ComboBox1.Value = 0

    TextBox1.Text = "TextBox1"
    TextBox1.ShowDropButtonWhen = 2 'fmShowDropButtonWhenAlways
    TextBox1.Locked = True

    Label1.Caption = "TheDropButton also applies to a TextBox."
    Label1.AutoSize = True
    Label1.WordWrap = False
End Sub


DropDown Method Example

The following example uses the DropDown method to display the list in a ComboBox. The user can display the list of a ComboBox by clicking the CommandButton.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • A ComboBox named ComboBox1.
  • A CommandButton named CommandButton1.
Dim ComboBox1

Sub CommandButton1_Click()
    ComboBox1.DropDown
End Sub

Sub Item_Open()
     Set ComboBox1 = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls("ComboBox1")
    ComboBox1.AddItem "Turkey"
    ComboBox1.AddItem "Chicken"
    ComboBox1.AddItem "Duck"
    ComboBox1.AddItem "Goose"
    ComboBox1.AddItem "Grouse"
End Sub


Enabled, Locked Properties Example

The following example demonstrates the Enabled and Locked properties and how they complement each other. This example exposes each property independently with a CheckBox, so you observe the settings individually and combined. This example also includes a second TextBox so you can copy and paste information between the TextBox controls and verify the activities supported by the settings of these properties.

Note You can copy the selection to the Clipboard using CTRL+C and paste using CTRL+V.

To use this example, copy this sample code to the Script Editor of a form. Make sure that the form contains:

  • A TextBox named TextBox1.
  • Two CheckBox controls named CheckBox1 and CheckBox2.
  • A second TextBox named TextBox2.
Dim TextBox1
Dim TextBox2
Dim CheckBox1
Dim CheckBox2

Sub CheckBox1_Click()
    TextBox2.Text = "TextBox2"
    TextBox1.Enabled = CheckBox1.Value
End Sub

Sub CheckBox2_Click()
    TextBox2.Text = "TextBox2"
    TextBox1.Locked = CheckBox2.Value
End Sub

Sub Item_Open()
     Set TextBox1 = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls("TextBox1")
     Set TextBox2 = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls("TextBox2")
     Set CheckBox1 = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls("CheckBox1")
     Set CheckBox2 = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls("CheckBox2")

    TextBox1.Text = "TextBox1"
    TextBox1.Enabled = True
    TextBox1.Locked = False

    CheckBox1.Caption = "Enabled"
    CheckBox1.Value = True

    CheckBox2.Caption = "Locked"
    CheckBox2.Value = False

    TextBox2.Text = "TextBox2"
End Sub


EnterKeyBehavior Property Example

The following example uses the EnterKeyBehavior property to control the effect of ENTER in a TextBox. In this example, the user can specify either a single-line or multiline TextBox.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • A TextBox named TextBox1.
  • Two ToggleButton controls named ToggleButton1 and ToggleButton2.
Dim TextBox1
Dim ToggleButton1
Dim ToggleButton2

Sub Item_Open()
    set TextBox1 = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls("TextBox1")
    set ToggleButton1 = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls("ToggleButton1")
    set ToggleButton2 = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls("ToggleButton2")
    TextBox1.EnterKeyBehavior = True
    ToggleButton1.Caption = "EnterKeyBehavior is True"
    ToggleButton1.Width = 70
    ToggleButton1.Value = True

    TextBox1.MultiLine = True
    ToggleButton2.Caption = "MultiLine is True"
    ToggleButton2.Width = 70
    ToggleButton2.Value = True

    TextBox1.Height = 100
    TextBox1.WordWrap = True
    TextBox1.Text = "Type your text here. If EnterKeyBehavior is True,"& _
    " press Enter to start a new line. Otherwise, press SHIFT+ENTER."
End Sub

Sub ToggleButton1_Click()
    If ToggleButton1.Value = True Then
        TextBox1.EnterKeyBehavior = True
        ToggleButton1.Caption = "EnterKeyBehavior is True"
    Else
        TextBox1.EnterKeyBehavior = False
        ToggleButton1.Caption = "EnterKeyBehavior is False"
    End If
End Sub

Sub ToggleButton2_Click()
    If ToggleButton2.Value = True Then
        TextBox1.MultiLine = True
        ToggleButton2.Caption = "MultiLine TextBox"
    Else
        TextBox1.MultiLine = False
        ToggleButton2.Caption = "Single-line TextBox"
    End If
End Sub


Exp function example

This example returns e.

Exp(1)


Int, Fix function examples

The following examples illustrate how the Int and Fix functions return integer portions of numbers. In the case of a negative number argument, the Int function returns the first negative integer less than or equal to the number; the Fix function returns the first negative integer greater than or equal to the number.

Function | Returns
Int(99.8) | 99
Fix(99.2) | 99
Int(-99.8) | -100
Fix (-99.8) | -99
Int(-99.2) | -100
Fix(-99.2) | -99


Format function example

This example shows various uses of the Format function to format values by using both named and user-defined formats. For the date separator (/), time separator (:), and AM/ PM literal, the actual formatted output displayed by your system depends on the locale settings on which the code is running. When displayed in a field, the short time and short date formats of the system locale are used, which may differ from the code locale. For these examples, English/United States is assumed.

Function | Returns
Format([Received], "h:m:s") | 17:4:23
Format([Received], "Long Time") | 17:4:23 PM
Format([Received], "Long Date") | Monday, January 27, 1997
Format([Received], "hh:mm:ss AMPM") | 05:04:23 PM
Format([Received], "dddd, mmm d yyyy") | Monday, Jan 27 1997

Function | Returns
Format(23) | 23
Format(5459.4, "##,##0.00") | 5,459.40
Format(334.9, "###0.00") | 334.90
Format(5, "0.00%") | 500.00%
Format("HELLO", "<") | hello
Format("This is it", ">") | THIS IS IT


FV function example

This example uses the FV function to return the future value of an investment given the percentage rate that accrues per period (APR / 12), the total number of payments (TotPmts), the payment (Payment), the current value of the investment (PVal), and a number that indicates whether the payment is made at the beginning or end of the payment period (PayType). Note that because Payment represents cash paid out, it's a negative number.

FV([APR] / 12, [TotPmts], -[Payment], -[PVal], [PayType])


GroupName Property Example

The following example uses the GroupName property to create two groups of OptionButton controls on the same form.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains five OptionButton controls named OptionButton1 through OptionButton5.

Sub Item_Open()
    set OptionButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("OptionButton1")
    set OptionButton2 = Item.GetInspector.ModifiedFormPages("P.2").Controls("OptionButton2")
    set OptionButton3 = Item.GetInspector.ModifiedFormPages("P.2").Controls("OptionButton3")
    set OptionButton4 = Item.GetInspector.ModifiedFormPages("P.2").Controls("OptionButton4")
    set OptionButton5 = Item.GetInspector.ModifiedFormPages("P.2").Controls("OptionButton5")

    OptionButton1.Caption = "Widgets"
    OptionButton2.Caption = "Widgets"
    OptionButton3.Caption = "Widgets"
    OptionButton1.GroupName = "Widgets"
    OptionButton2.GroupName = "Widgets"
    OptionButton3.GroupName = "Widgets"

    OptionButton4.Caption = "Gadgets-Group2"
    OptionButton5.Caption = "Gadgets-Group2"
    OptionButton4.GroupName = "Gadgets-Group2"
    OptionButton5.GroupName = "Gadgets-Group2"
End Sub


Hex function example

The following examples use the Hex function to return the hexadecimal value of values for the Number field.

Number field | Function returns
5 | 5
10 | A
459 | 1CB

Hex([Number])


Hour function example

The following example uses the Hour function to return the hour of the Received field.

Hour([Received])


IIf function example

The following example uses the IIf function to return the word "Large" if the value of the Size field is greater than 10000; otherwise, it returns the word "Small".

IIf([Size] > 10000, "Large", "Small")


Index Property Example

The following example uses the Index property to change the order of the pages and tabs in a MultiPage and TabStrip. The user chooses CommandButton1 to move the third page and tab to the front of the MultiPage and TabStrip. The user chooses CommandButton2 to move the selected page and tab to the back of the MultiPage and TabStrip.

To use this example, copy this sample code to the Script Editor of a form. Make sure that the form contains:

  • Two CommandButton controls named CommandButton1 and CommandButton2.
  • A MultiPage named MultiPage1.
  • A TabStrip named TabStrip1.
Dim MyPageOrTab
Dim MultiPage1
Dim TabStrip1

Sub CommandButton1_Click()
'Move third page and tab to front of control
    MultiPage1.page3.Index = 0
    TabStrip1.Tab3.Index = 0
End Sub

Sub CommandButton2_Click()
'Move selected page and tab to back of control
    Set MyPageOrObject = MultiPage1.SelectedItem
    MsgBox "MultiPage1.SelectedItem = " & MultiPage1.SelectedItem.Name
    MyPageOrObject.Index = 4

    Set MyPageOrObject = TabStrip1.SelectedItem
    MsgBox "TabStrip1.SelectedItem = " & TabStrip1.SelectedItem.Caption
    MyPageOrObject.Index = 4
End Sub

Sub Item_Open()
     Set MultiPage1 = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls("MultiPage1")
     Set TabStrip1 = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls("TabStrip1")
     Set CommandButton1 = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls("CommandButton1")
     Set CommandButton2 = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls("CommandButton2")

    MultiPage1.Width = 200
    MultiPage1.Pages.Add
    MultiPage1.Pages.Add
    MultiPage1.Pages.Add

    TabStrip1.Width = 200
    TabStrip1.Tabs.Add
    TabStrip1.Tabs.Add
    TabStrip1.Tabs.Add

    CommandButton1.Caption = "Move third page/tab to front"
    CommandButton1.Width = 120

    CommandButton2.Caption = "Move selected item to back"
    CommandButton2.Width = 120
 End Sub


InsideHeight, InsideWidth Properties Example

The following example uses the InsideHeight and InsideWidth properties to resize a CommandButton. The user clicks the CommandButton to resize it.

Note InsideHeight and InsideWidth are read-only properties.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • A CommandButton named CommandButton1.
Dim Resize

Sub Item_Open()
    Set CommandButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("CommandButton1")

    Resize = 0.75
    CommandButton1.Caption = "Resize Button"

End Sub

Sub CommandButton1_Click()
    Set Form = Item.GetInspector.ModifiedFormPages("P.2")
    Set CommandButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("CommandButton1")

    CommandButton1.Move 10, 10, Form.InsideWidth * Resize, Form.InsideHeight * Resize
    CommandButton1.Caption = "Button resized using InsideHeight and InsideWidth!"
End Sub


InStr function example

The following example uses the InStr function to return the position of the first occurrence of the letter S within the Subject field.

Subject field | Function returns
International Sales | 11
Marketing Strategy | 15

InStr(1, [Subject], "S", 1)


IPmt function example

This example uses the IPmt function to calculate how much of a payment is interest when all the payments are of equal value. Given are the interest percentage rate per period (APR / 12), the payment period for which the interest portion is desired (Period), the total number of payments (TotPmts), the present value or principal of the loan (PVal), the future value of the loan (FVal), and a number that indicates whether the payment is due at the beginning or end of the payment period (PayType).

IPmt([APR] / 12, [Period], [TotPmts], -[PVal], [FVal], [PayType])


IsDate function example

The following example uses the IsDate function to determine whether the Other field can be converted to a date.

IsDate([Other])


Item Method Example

The following example uses the Item method to access individual members of the Controls and Pages collections. The user chooses an option button for either the Controls collection or the MultiPage, and then clicks the CommandButton. The name of the appropriate control is returned in the Label.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • A CommandButton named CommandButton1.
  • A Label named Label1.
  • Two OptionButton controls named OptionButton1 and OptionButton2.
  • A MultiPage named MultiPage1.
Dim ControlsIndex

Sub CommandButton1_Click()
    Set Controls = Item.GetInspector.ModifiedFormPages("P.2").Controls
    Set OptionButton1 = Controls("OptionButton1")
    Set OptionButton2 = Controls("OptionButton2")
    Set Label1 = Controls("Label1")
    Set MultiPage1 = Controls("MultiPage1")

    If OptionButton1.Value = True Then
        'Process Controls collection for UserForm
        Set MyControl = Controls.Item(ControlsIndex)
        Label1.Caption = MyControl.Name

        'Prepare index for next control on Userform
        ControlsIndex = ControlsIndex + 1
        If ControlsIndex >= Controls.Count Then
            ControlsIndex = 0
        End If

    ElseIf OptionButton2.Value = True Then
        'Process Current Page of Pages collection
        Set MyControl = MultiPage1.Pages.Item(MultiPage1.Value)
        Label1.Caption = MyControl.Name
    End If
End Sub

Sub Item_Open()
    ControlsIndex = 0

    Set OptionButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("OptionButton1")
    Set OptionButton2 = Item.GetInspector.ModifiedFormPages("P.2").Controls("OptionButton2")
    Set CommandButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("CommandButton1")

    OptionButton1.Caption = "Controls Collection"
    OptionButton2.Caption = "Pages Collection"
    OptionButton1.Value = True

    CommandButton1.Caption = "Get Member Name"
End Sub


LargeChange, SmallChange Properties Example

The following example demonstrates the LargeChange and SmallChange properties when used with a stand-alone ScrollBar. The user can set the LargeChange and SmallChange values to any integer in the range of 0 to 100. This example also uses the MaxLength property to restrict the number of characters entered for the LargeChange and SmallChange values.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • A Label named Label1
  • A TextBox named TextBox1 that is bound to the custom number field named ScrollBarSmallChange
  • A Label named Label2
  • A TextBox named TextBox2 that is bound to the custom number field named ScrollBarLargeChange.
  • A ScrollBar named ScrollBar1 that is bound to the custom number field named ScrollBarValue.
  • A Label named Label3.
Sub Item_Open()
    Set Label1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("Label1")
    Set ScrollBar1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ScrollBar1")
    Set TextBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TextBox1")
    Set Label2 = Item.GetInspector.ModifiedFormPages("P.2").Controls("Label2")
    Set TextBox2 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TextBox2")
    Set Label3 = Item.GetInspector.ModifiedFormPages("P.2").Controls("Label3")

    ScrollBar1.Min = -1000
    ScrollBar1.Max = 1000

    Label1.Caption = "SmallChange 0 to 100"
    ScrollBar1.SmallChange = 1
    TextBox1.Text = ScrollBar1.SmallChange
    TextBox1.MaxLength = 3

    Label2.Caption = "LargeChange 0 to 100"
    ScrollBar1.LargeChange = 100
    TextBox2.Text = ScrollBar1.LargeChange
    TextBox2.MaxLength = 3

    ScrollBar1.Value = 0
    Label3.Caption = ScrollBar1.Value
End Sub

Sub Item_CustomPropertyChange(byval pname)
    Set ScrollBar1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ScrollBar1")
    Set TextBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TextBox1")
    Set TextBox2 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TextBox2")
    Set Label3 = Item.GetInspector.ModifiedFormPages("P.2").Controls("Label3")

    If pname = "ScrollBarMin" Then

        If IsNumeric(TextBox1.Text) Then
            TempNum = CInt(TextBox1.Text)
            If TempNum >= 0 And TempNum <= 100 Then
                ScrollBar1.SmallChange = TempNum
            Else
                TextBox1.Text = ScrollBar1.SmallChange
            End If
        Else
            TextBox1.Text = ScrollBar1.SmallChange
        End If

    ElseIf pname = "ScrollBarMax" Then

        If IsNumeric(TextBox2.Text) Then
            TempNum = CInt(TextBox2.Text)
            If TempNum >= 0 And TempNum <= 100 Then
                ScrollBar1.LargeChange = TempNum
            Else
                TextBox2.Text = ScrollBar1.LargeChange
            End If
        Else
            TextBox2.Text = ScrollBar1.LargeChange
        End If

    ElseIf pname = "ScrollBarValue" Then

        Label3.Caption = ScrollBar1.Value
    End If
End Sub


LCase function example

The following example returns lowercase values of the Subject field.

Subject field | Function returns
International Sales | international sales
Marketing Strategy | marketing strategy

LCase([Subject])


Left function example

The following example returns four characters from the left side of the Subject field.

Subject field | Function returns
International Sales | Inte
Marketing Strategy | Mark

Left([Subject], 4)


Len function example

The following example uses the Len function to return the number of characters in the Subject field.

Subject field | Function returns
International Sales | 19
Marketing Strategy | 18

Len([Subject])


LineCount, TextLength Properties Example

The following example counts the characters and the number of lines of text in a TextBox by using the LineCount and TextLength properties, and the SetFocus method. In this example, the user can type into a TextBox, and can retrieve current values of the LineCount and TextLength properties.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains the following controls:

  • A TextBox named TextBox1.
  • A CommandButton named CommandButton1.
  • Two Label controls named Label1 and Label2.
'Type SHIFT+ENTER to start a new line in the text box.

Dim CommandButton1
Dim TextBox1
Dim Label1
Dim Label2

Sub CommandButton1_Click()
    'Must first give TextBox1 the focus to get line count
    TextBox1.SetFocus
    Label1.Caption = "LineCount = " & TextBox1.LineCount
    Label2.Caption = "TextLength = " & TextBox1.TextLength
End Sub

Sub Item_Open()
     Set TextBox1 = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls("TextBox1")
     Set Label1 = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls("Label1")
     Set Label2 = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls("Label2")
     Set CommandButton1 = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls("CommandButton1")

    CommandButton1.WordWrap = True
    CommandButton1.AutoSize = True
    CommandButton1.Caption = "Get Counts"

    Label1.Caption = "LineCount = "
    Label2.Caption = "TextLength = "

    TextBox1.MultiLine = True
    TextBox1.WordWrap = True
    TextBox1.Text = "Enter your text here."
End Sub


ListBox Control Example

The following example adds and deletes the contents of a ListBox using the AddItem, RemoveItem, and SetFocus methods, and the ListIndex and ListCount properties.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • A ListBox named ListBox1.
  • Two CommandButton controls named CommandButton1 and CommandButton2.
Dim EntryCount
Dim Listbox1

Sub Item_Open()
  Set ListBox1 = Item.GetInspector.ModifiedFormPages("P.2").ListBox1
  Set CommandButton1 = Item.GetInspector.ModifiedFormPages("P.2").CommandButton1
  Set CommandButton2 = Item.GetInspector.ModifiedFormPages("P.2").CommandButton2
  EntryCount = 0
  CommandButton1.Caption = "Add Item"
  CommandButton2.Caption = "Remove Item"
End Sub

Sub CommandButton1_Click()
  EntryCount = EntryCount + 1
  ListBox1.AddItem (EntryCount & " - Selection")
End Sub

Sub CommandButton2_Click()
  ListBox1.SetFocus

  'Ensure ListBox contains list items
  If ListBox1.ListCount >= 1 Then
      'If no selection, choose last list item.
      If ListBox1.ListIndex = -1 Then
          ListBox1.ListIndex = ListBox1.ListCount - 1
      End If
      ListBox1.RemoveItem (ListBox1.ListIndex)
  End If
End Sub


List Property Example

The following example swaps columns of a multicolumn ListBox. The sample uses the List property in two ways:

  1. To access and exchange individual values in the ListBox. In this usage, List has subscripts to designate the row and column of a specified value.
  2. To initially load the ListBox with values from an array. In this usage, List has no subscripts.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains a ListBox named ListBox1 and a CommandButton named CommandButton1.

Dim Listbox1
Dim MyArray(6, 3)

Sub Item_Open
  Dim i
  Set Listbox1 = Item.GetInspector.ModifiedFormPages("P.2").Listbox1

  Listbox1.ColumnCount = 3
  For i = 0 to 5
    MyArray(i, 0) = i
    MyArray(i, 1) = Rnd
    MyArray(i, 2) = Rnd
  Next

  Listbox1.List() = MyArray
End Sub

Sub CommandButton1_Click
  Dim i
  Dim Temp

  For i = 0 to 5
    Temp = Listbox1.List(i, 0)
    Listbox1.List(i, 0) = Listbox1.List(i, 2)
    Listbox1.List(i, 2) = Temp
  Next
End Sub


ListRows Property Example

The following example uses a SpinButton to control the number of rows in the drop-down list of a ComboBox. The user changes the value of the SpinButton, then clicks on the drop-down arrow of the ComboBox to display the list.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • A ComboBox named ComboBox1.
  • A SpinButton named SpinButton1 that is bound to a custom number field named SpinButtonValue.
  • A Label named Label1.
Sub Item_Open()
    Set ComboBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ComboBox1")
    Set SpinButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("SpinButton1")
    Set Label1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("Label1")

    For i = 1 To 20
        ComboBox1.AddItem "Choice " & (ComboBox1.ListCount + 1)
    Next

    SpinButton1.Min = 0
    SpinButton1.Max = 12
    SpinButton1.Value = ComboBox1.ListRows
    Label1.Caption = "ListRows = " & SpinButton1.Value
End Sub

Sub Item_CustomPropertyChange(byval pname)
    If pname = "SpinButtonValue" Then
        Set ComboBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ComboBox1")
        Set SpinButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("SpinButton1")
        Set Label1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("Label1")

            ComboBox1.ListRows = SpinButton1.Value
        Label1.Caption = "ListRows = " & SpinButton1.Value
    End If
End Sub


ListStyle, MultiSelect Properties Example

The following example uses the ListStyle and MultiSelect properties to control the appearance of a ListBox. The user chooses a value for ListStyle using the ToggleButton and chooses an OptionButton for one of the MultiSelect values. The appearance of the ListBox changes accordingly, as well as the selection behavior within the ListBox.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • A ListBox named ListBox1.
  • A Label named Label1.
  • Three OptionButton controls named OptionButton1 through OptionButton3.
  • A ToggleButton named ToggleButton1.
Sub Item_Open()
    Set ListBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ListBox1")
    Set Label1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("Label1")
    Set OptionButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("OptionButton1")
    Set OptionButton2 = Item.GetInspector.ModifiedFormPages("P.2").Controls("OptionButton2")
    Set OptionButton3 = Item.GetInspector.ModifiedFormPages("P.2").Controls("OptionButton3")
    Set ToggleButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ToggleButton1")

    For i = 1 To 8
        ListBox1.AddItem "Choice" & (ListBox1.ListCount + 1)
    Next

    Label1.Caption = "MultiSelect Choices"
    Label1.AutoSize = True

    ListBox1.MultiSelect = 0        '0=fmMultiSelectSingle
    OptionButton1.Caption = "Single entry"
    OptionButton1.Value = True
    OptionButton2.Caption = "Multiple entries"
    OptionButton3.Caption = "Extended entries"

    ToggleButton1.Caption = "ListStyle - Plain"
    ToggleButton1.Value = True
    ToggleButton1.Width = 90
    ToggleButton1.Height = 30
End Sub

Sub OptionButton1_Click()
    Set ListBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ListBox1")
    ListBox1.MultiSelect = 0        '0=fmMultiSelectSingle
End Sub

Sub OptionButton2_Click()
    Set ListBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ListBox1")
    ListBox1.MultiSelect = 1        '1=fmMultiSelectMulti
End Sub

Sub OptionButton3_Click()
    Set ListBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ListBox1")
    ListBox1.MultiSelect = 2        '2=fmMultiSelectExtended
End Sub

Sub ToggleButton1_Click()
    Set ToggleButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ToggleButton1")
    Set ListBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ListBox1")

    If ToggleButton1.Value = True Then
        ToggleButton1.Caption = "Plain ListStyle"
        ListBox1.ListStyle = 0    '0=fmListStylePlain
    Else
        ToggleButton1.Caption = "OptionButton or CheckBox"
        ListBox1.ListStyle = 1    '1=fmListStyleOption
    End If
End Sub


ListWidth Property Example

The following example uses a SpinButton to control the width of the drop-down list of a ComboBox. The user changes the value of the SpinButton, then clicks on the drop-down arrow of the ComboBox to display the list.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • A ComboBox named ComboBox1.
  • A SpinButton named SpinButton1 that is bound to a custom number field named SpinButtonValue.
  • A Label named Label1.
Sub Item_Open()
    Set ComboBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ComboBox1")
    Set SpinButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("SpinButton1")
    Set Label1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("Label1")

    For i = 1 To 20
        ComboBox1.AddItem "Choice " & (ComboBox1.ListCount + 1)
    Next
    SpinButton1.Min = 0
    SpinButton1.Max = 130

    'convert listwidth value from '122 pt' to an integer
    intpos = instr(combobox1.listwidth," ")
    intwidth = left(combobox1.listwidth,intpos-1)
    SpinButton1.Value = intwidth
    SpinButton1.SmallChange = 5
    Label1.Caption = "ListWidth = " & SpinButton1.Value
End Sub

Sub Item_CustomPropertyChange(byval pname)
    If pname = "SpinButtonValue" Then
        Set ComboBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ComboBox1")
        Set SpinButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("SpinButton1")
        Set Label1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("Label1")

    ComboBox1.ListWidth = SpinButton1.Value
    Label1.Caption = "ListWidth = " & SpinButton1.Value
    End If
End Sub


Log function example

The following example returns the natural logarithm for the numeric field Angle.

Log([Angle] + Sqr([Angle] * [Angle] + 1))


LTrim, RTrim, and Trim function examples

The following examples use the LTrim and RTrim functions to strip leading and trailing spaces, respectively, from a Subject field that contains the value " <-Trim-> ". It uses the Trim function alone to strip both types of spaces. The quotation marks mark the end of the string but are not part of it.

Function | Returns
LTrim([Subject]) | "<-Trim-> "
RTrim([Subject]) | " <-Trim->"
Trim([Subject]) | "<-Trim->"


MatchEntry Property Example

The following example uses the MatchEntry property to demonstrate character matching that is available for ComboBox and ListBox. In this example, the user can set the type of matching with the OptionButton controls and then type into the ComboBox to specify an item from its list.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • Three OptionButton controls named OptionButton1 through OptionButton3.
  • A ComboBox named ComboBox1.
Sub OptionButton1_Click()
    Set ComboBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ComboBox1")
    ComboBox1.MatchEntry = 2        '2=fmMatchEntryNone
End Sub

Sub OptionButton2_Click()
    Set ComboBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ComboBox1")
    ComboBox1.MatchEntry = 0        '0=fmMatchEntryFirstLetter
End Sub

Sub OptionButton3_Click()
    Set ComboBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ComboBox1")
        ComboBox1.MatchEntry = 1    '1=fmMatchEntryComplete
End Sub

Sub Item_Open()
    Set ComboBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ComboBox1")
    Set OptionButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("OptionButton1")
    Set OptionButton2 = Item.GetInspector.ModifiedFormPages("P.2").Controls("OptionButton2")
    Set OptionButton3 = Item.GetInspector.ModifiedFormPages("P.2").Controls("OptionButton3")

    For i = 1 To 9
        ComboBox1.AddItem "Choice " & i
    Next
    ComboBox1.AddItem "Chocoholic"

    OptionButton1.Caption = "No matching"
    OptionButton1.Value = True

    OptionButton2.Caption = "Basic matching"
    OptionButton3.Caption = "Extended matching"
End Sub


MatchFound, MatchRequired Properties Example

The following example uses the MatchFound and MatchRequired properties to demonstrate additional character matching for ComboBox. The matching verification occurs in the Change event.

In this example, the user specifies whether the text portion of a ComboBox must match one of the listed items in the ComboBox. The user can specify whether matching is required by using a CheckBox and then type into the ComboBox to specify an item from its list.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • A ComboBox named ComboBox1 that is bound to the Subject field.
  • A CheckBox named CheckBox1.
Sub CheckBox1_Click()
    Set ComboBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ComboBox1")
    Set CheckBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("CheckBox1")

    If CheckBox1.Value = True Then
        ComboBox1.MatchRequired = True
        MsgBox "To move the focus from the ComboBox, you must match an entry in the list or press ESC."
    Else
        ComboBox1.MatchRequired = False
        MsgBox " To move the focus from the ComboBox, just tab to or click another control. Matching is optional."
    End If
End Sub

Sub Item_PropertyChange(byval pname)
    if pname = "Subject" then
        Set ComboBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ComboBox1")
        If ComboBox1.MatchRequired = True Then
        'MSForms handles this case automatically
        Else
            If ComboBox1.MatchFound = True Then
                MsgBox "Match Found; matching optional."
            Else
                MsgBox "Match not Found; matching optional."
            End If
        End If
    end if
End Sub

Sub Item_Open()
    Set ComboBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ComboBox1")
    Set CheckBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("CheckBox1")

    For i = 1 To 9
            ComboBox1.AddItem "Choice " & i
    Next
    ComboBox1.AddItem "Chocoholic"

    CheckBox1.Caption = "MatchRequired"
    CheckBox1.Value = True
End Sub


Max, Min, MaxLength Properties Example

The following example demonstrates the Max and Min properties when used with a stand-alone ScrollBar. The user can set the Max and Min values to any integer in the range of –1000 to 1000. This example also uses the MaxLength property to restrict the number of characters entered for the Max and Min values.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • A Label named Label1
  • A TextBox named TextBox1 that is bound to the custom number field named ScrollBarMin.
  • A Label named Label2
  • A TextBox named TextBox2 that is bound to the custom number field named ScrollBarMax.
  • A ScrollBar named ScrollBar1 that is bound to the custom number field named ScrollBarValue.
  • A Label named Label3.
Sub Item_Open()
    Set Label1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("Label1")
    Set ScrollBar1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ScrollBar1")
    Set TextBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TextBox1")
    Set Label2 = Item.GetInspector.ModifiedFormPages("P.2").Controls("Label2")
    Set TextBox2 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TextBox2")
    Set Label3 = Item.GetInspector.ModifiedFormPages("P.2").Controls("Label3")

    Label1.Caption = "Min -1000 to 1000"
    ScrollBar1.Min = -1000
    TextBox1.Text = ScrollBar1.Min
    TextBox1.MaxLength = 5

    Label2.Caption = "Max -1000 to 1000"
    ScrollBar1.Max = 1000
    TextBox2.Text = ScrollBar1.Max
    TextBox2.MaxLength = 5

    ScrollBar1.SmallChange = 1
    ScrollBar1.LargeChange = 100
    ScrollBar1.Value = 0
    Label3.Caption = ScrollBar1.Value
End Sub

Sub Item_CustomPropertyChange(byval pname)
    Set ScrollBar1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ScrollBar1")
    Set TextBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TextBox1")
    Set TextBox2 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TextBox2")
    Set Label3 = Item.GetInspector.ModifiedFormPages("P.2").Controls("Label3")

    If pname = "ScrollBarMin" Then

        If IsNumeric(TextBox1.Text) Then
                TempNum = CInt(TextBox1.Text)
            If TempNum >= -1000 And TempNum <= 1000 Then
                    ScrollBar1.Min = TempNum
                Else
                    TextBox1.Text = ScrollBar1.Min
            End If
            Else
                TextBox1.Text = ScrollBar1.Min
        End If
    ElseIf pname = "ScrollBarMax" Then

        If IsNumeric(TextBox2.Text) Then
                TempNum = CInt(TextBox2.Text)
                If TempNum >= -1000 And TempNum <= 1000 Then
                    ScrollBar1.Max = TempNum
            Else
                    TextBox2.Text = ScrollBar1.Max
                End If
        Else
                TextBox2.Text = ScrollBar1.Max
        End If
    ElseIf pname = "ScrollBarValue" Then

        Label3.Caption = ScrollBar1.Value
    End If
End Sub


Mid function example

The following example uses the Mid function to return a specified number of characters from the Subject field with the value "Marketing Strategy".

Function | Returns
Mid ([Subject], 1, 3) | Mar
Mid ([Subject], 11, 8) | Strategy
Mid ([Subject], 5) | eting Strategy


Minute function example

The following example uses the Minute function to return the minute of the Received field.

Minute([Received])


Month function example

The following example uses the Month function to return the month of the Received field.

Month([Received])


MouseIcon, MousePointer Properties Example

The following example demonstrates how to specify a mouse pointer that is appropriate for a specific control or situation. You can assign one of several available mouse pointers using the MousePointer property.

This example works in the following ways:

  • Choose a mouse pointer from the ListBox to change the mouse pointer associated with the ListBox.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • A ListBox named ListBox1.
Dim ListBox1

Sub Item_Open()
    set ListBox1 = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls("ListBox1")
    'Load ListBox with MousePointer choices
    ListBox1.Clear
    ListBox1.AddItem "Default"
    ListBox1.AddItem "Arrow"
    ListBox1.AddItem "Cross"
    ListBox1.AddItem "IBeam"
    ListBox1.AddItem "SizeNESW"
    ListBox1.AddItem "SizeNS"
    ListBox1.AddItem "SizeNWSE"
    ListBox1.AddItem "SizeWE"
    ListBox1.AddItem "UpArrow"
    ListBox1.AddItem "Hourglass"
    ListBox1.AddItem "NoDrop"
    ListBox1.AddItem "AppStarting"
    ListBox1.AddItem "Help"
    ListBox1.AddItem "SizeAll"
End Sub

Sub ListBox1_Click()
   If IsNull(ListBox1.Value) = False Then
    Select Case ListBox1.Value
        Case "Default"
            pointer = 0        'Standard pointer.
            Case "Arrow"
            pointer = 1        'Arrow.
        Case "Cross"
            pointer = 2        'Cross-hair pointer.
        Case "IBeam"
            pointer = 3        'I-beam.
        Case "SizeNESW"
            pointer = 6        'Double arrow pointing northeast and southwest.
        Case "SizeNS"
            pointer = 7        'Double arrow pointing north and south.
         Case "SizeNWSE"
            pointer = 8        'Double arrow pointing northwest and southeast.
        Case "SizeWE"
            pointer = 9        'Double arrow pointing west and east.
        Case "UpArrow"
            pointer = 10    'Up arrow.
        Case "Hourglass"
            pointer = 11    'Hourglass.
        Case "NoDrop"
            pointer = 12    '"Not" symbol (circle with a diagonal line) on top of the object being dragged. Indicates an invalid drop target.
        Case "AppStarting"
            pointer = 13    'Arrow with an hourglass.
        Case "Help"
            pointer = 14    'Arrow with a question mark.
        Case "SizeAll"
            pointer = 15    'Size all cursor (arrows pointing north, south, east, and west).
    End Select
    ListBox1.MousePointer = pointer
   End If
End Sub


Move Method Example for Controls Collection

The following example demonstrates moving all the controls on a form by using the Move method with the Controls collection. The user clicks on the CommandButton to move the controls.

To use this example, copy this sample code to the Script Editor of a form. Make sure that the form contains a CommandButton named CommandButton1 and several other controls.

Sub CommandButton1_Click()
  Set Controls = Item.GetInspector.ModifiedFormPages("P.2").Controls
  'Move each control on the form right 25 points and up 25 points.
  Controls.Move 25, -25
End Sub


MultiLine, WordWrap, ScrollBars Properties Example

The following example demonstrates the MultiLine, WordWrap, and ScrollBars properties on a TextBox.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • A TextBox named TextBox1.
  • Four ToggleButton controls named ToggleButton1 through ToggleButton4.

To see the entire text placed in the TextBox, set MultiLine and WordWrap to True by clicking the ToggleButton controls.

When MultiLine is True, you can enter new lines of text by pressing SHIFT+ENTER.

ScrollBars appears when you manually change the content of the TextBox.

Dim ToggleButton1
Dim ToggleButton2
Dim ToggleButton3
Dim ToggleButton4
Dim TextBox1

Sub Item_Open
'Initialize TextBox properties and toggle buttons

  Set ToggleButton1 = Item.GetInspector.ModifiedFormPages("P.2").ToggleButton1
  Set ToggleButton2 = Item.GetInspector.ModifiedFormPages("P.2").ToggleButton2
  Set ToggleButton3 = Item.GetInspector.ModifiedFormPages("P.2").ToggleButton3
  Set ToggleButton4 = Item.GetInspector.ModifiedFormPages("P.2").ToggleButton4
  Set TextBox1 = Item.GetInspector.ModifiedFormPages("P.2").TextBox1

  TextBox1.Text = "Type your text here.  Enter SHIFT+ENTER to move to a new line."
  TextBox1.AutoSize = False
  ToggleButton1.Caption = "AutoSize Off"
  ToggleButton1.Value = False
  ToggleButton1.AutoSize = True

  TextBox1.WordWrap = False
  ToggleButton2.Caption = "WordWrap Off"
  ToggleButton2.Value = False
  ToggleButton2.AutoSize = True

  TextBox1.ScrollBars = 0
  ToggleButton3.Caption = "ScrollBars Off"
  ToggleButton3.Value = False
  ToggleButton3.AutoSize = True

  TextBox1.MultiLine = False
  ToggleButton4.Caption = "Single Line"
  ToggleButton4.Value = False
  ToggleButton4.AutoSize = True

End Sub

Sub ToggleButton1_Click
'Set AutoSize property and associated ToggleButton

  If ToggleButton1.Value = True Then
    TextBox1.AutoSize = True
    ToggleButton1.Caption = "AutoSize On"
  Else
    TextBox1.AutoSize = False
    ToggleButton1.Caption = "AutoSize Off"
  End if
End Sub

Sub ToggleButton2_Click
'Set WordWrap property and associated  ToggleButton

  If ToggleButton2.Value = True Then
    TextBox1.WordWrap = True
    ToggleButton2.Caption = "WordWrap On"
  Else
    TextBox1.WordWrap = False
    ToggleButton2.Caption = "WordWrap Off"
  End if
End Sub

Sub ToggleButton3_Click
'Set ScrollBars property and associated ToggleButton

  If ToggleButton3.Value = True Then
    TextBox1.ScrollBars = 3
    ToggleButton3.Caption = "ScrollBars On"
  Else
    TextBox1.ScrollBars = 0
    ToggleButton3.Caption = "ScrollBars Off"
  End if
End Sub

Sub ToggleButton4_Click
'Set MultiLine property and associated ToggleButton

  If ToggleButton4.Value = True Then
    TextBox1.MultiLine = True
    ToggleButton4.Caption = "Multiple Lines"
  Else
    TextBox1.MultiLine = False
    ToggleButton4.Caption = "Single Line"
  End if
 End Sub


MultiSelect, Selected Properties Example

The following example uses the MultiSelect and Selected properties to demonstrate how the user can select one or more items in a ListBox. The user specifies a selection method by choosing an option button and then selects an item(s) from the ListBox. The user can display the selected items in a second ListBox by clicking the CommandButton.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • Two ListBox controls named ListBox1 and ListBox2.
  • A CommandButton named CommandButton1.
  • Three OptionButton controls named OptionButton1 through OptionButton3.
Sub CommandButton1_Click()
    Set ListBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ListBox1")
    Set ListBox2 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ListBox2")
    ListBox2.Clear

    For i = 0 To 9
        If ListBox1.Selected(i) = True Then
            ListBox2.AddItem ListBox1.List(i)
        End If
    Next

End Sub

Sub OptionButton1_Click()
    Set ListBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ListBox1")
    ListBox1.MultiSelect = 0        '0=fmMultiSelectSingle
End Sub

Sub OptionButton2_Click()
    Set ListBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ListBox1")
    ListBox1.MultiSelect = 1        '1=fmMultiSelectMulti
End Sub

Sub OptionButton3_Click()
    Set ListBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ListBox1")
    ListBox1.MultiSelect = 2        '2=fmMultiSelectExtended
End Sub

Sub Item_Open()
    Set ListBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ListBox1")
    Set OptionButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("OptionButton1")
    Set OptionButton2 = Item.GetInspector.ModifiedFormPages("P.2").Controls("OptionButton2")
    Set OptionButton3 = Item.GetInspector.ModifiedFormPages("P.2").Controls("OptionButton3")
    Set CommandButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("CommandButton1")

    For i = 0 To 9
        ListBox1.AddItem "Choice " & (ListBox1.ListCount + 1)
    Next

    OptionButton1.Caption = "Single Selection"
    ListBox1.MultiSelect = 0        '0=fmMultiSelectSingle
    OptionButton1.Value = True

    OptionButton2.Caption = "Multiple Selection"
    OptionButton3.Caption = "Extended Selection"

    CommandButton1.Caption = "Show selections"
    CommandButton1.AutoSize = True
End Sub


Name Property Example

The following example displays the Name property of each control on a form. This example uses the Controls collection to cycle through all the controls placed directly on the User form.

To use this example, copy this sample code to the Script Editor of a form. Make sure that the form contains a CommandButton named CommandButton1 and several other controls.

Sub CommandButton1_Click()
    Set Controls = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls
    For i = 0 to Controls.Count - 1
        MsgBox "MyControl.Name = " & Controls.Item(i).Name
    Next
End Sub


Now function example

The following example uses the Now function to return the number of days since an item was received.

DateValue(Now())-DateValue([Received]) & " Day(s)"


NPer function example

This example uses the NPer function to return the number of periods over which payments must be made to pay off a loan whose value is contained in PVal. Also provided are the interest percentage rate per period (APR / 12), the payment (Payment), the future value of the loan (FVal), and a number that indicates whether the payment is due at the beginning or end of the payment period (PayType).

IPmt([APR] / 12, [Period], [TotPmts], -[PVal], [FVal], [PayType])


Object Property Example

Assume a new control has a Top property that is different from the standard Top property in Microsoft Forms. You can use either property, based on the syntax:

  • control.Top uses the standard Top property.
  • control.Object.Top uses the Top property from the added control.


Oct function example

The following examples use the Oct function to return the octal value of values for the Number field.

Number field | Function returns
4 | 4
8 | 10
459 | 713

Oct([Number])


Parent Property Example

The following example uses the Parent property to refer to the control or form that contains a specific control.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • Two Label controls named Label1 and Label2.
  • A CommandButton named CommandButton1.
  • One or more additional controls of your choice.
Dim MyControl
Dim MyParent
Dim ControlsIndex

Sub Item_Open()
  Set CommandButton1 = Item.GetInspector.ModifiedFormPages("P.2").CommandButton1
  ControlsIndex = 0
  CommandButton1.Caption = "Get Control and Parent"
  CommandButton1.AutoSize = True
  CommandButton1.WordWrap = True
End Sub

Sub CommandButton1_Click()
  Set Label1 = Item.GetInspector.ModifiedFormPages("P.2").Label1
  Set Label2 = Item.GetInspector.ModifiedFormPages("P.2").Label2

  'Process Controls collection for UserForm
  Set MyControl = Item.GetInspector.ModifiedFormPages("P.2").Controls.Item(ControlsIndex)
  Set MyParent = MyControl.Parent
  Label1.Caption = MyControl.Name
  Label2.Caption = MyParent.Name

  'Prepare index for next control on Userform
  ControlsIndex = ControlsIndex + 1
  If ControlsIndex >= Item.GetInspector.ModifiedFormPages("P.2").Controls.Count Then
    ControlsIndex = 0
  End If
End Sub


Picture, PicturePosition Properties Example

The following example uses a ComboBox to show the picture placement options for a control. Each time the user clicks a list choice, the picture and caption are updated on the CommandButton. This code sample also uses the AddItem method to populate the ComboBox choices.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • A Label named Label1.
  • A CommandButton named CommandButton1 with the Picture property set to use an image on your computer.
  • A ComboBox named ComboBox1.
Dim Label1
Dim CommandButton1
Dim ComboBox1

Sub Item_Open()
Set Label1 = Item.GetInspector.ModifiedFormPages("P.2").Label1
Set CommandButton1 = Item.GetInspector.ModifiedFormPages("P.2").CommandButton1
Set ComboBox1 = Item.GetInspector.ModifiedFormPages("P.2").ComboBox1

    Label1.Left = 18
    Label1.Top = 12
    Label1.Height = 12
    Label1.Width = 190
    Label1.Caption = "Select picture placement relative to the caption."

    'Add list entries to combo box. The value of each entry matches the
    'corresponding ListIndex value in the combo box.
    ComboBox1.AddItem "Left Top"        'ListIndex = 0
    ComboBox1.AddItem "Left Center"     'ListIndex = 1
    ComboBox1.AddItem "Left Bottom"     'ListIndex = 2
    ComboBox1.AddItem "Right Top"       'ListIndex = 3
    ComboBox1.AddItem "Right Center"    'ListIndex = 4
    ComboBox1.AddItem "Right Bottom"    'ListIndex = 5

    ComboBox1.AddItem "Above Left"      'ListIndex = 6
    ComboBox1.AddItem "Above Center"    'ListIndex = 7
    ComboBox1.AddItem "Above Right"    'ListIndex = 8
    ComboBox1.AddItem "Below Left"      'ListIndex = 9
    ComboBox1.AddItem "Below Center"    'ListIndex = 10
    ComboBox1.AddItem "Below Right"    'ListIndex = 11

    ComboBox1.AddItem "Centered"        'ListIndex = 12

    ComboBox1.Style = 2  'Use drop-down list

    ComboBox1.BoundColumn = 0            'Combo box values are ListIndex values
    ComboBox1.ListIndex = 0              'Set combo box to first entry
    ComboBox1.Left = 18
    ComboBox1.Top = 36
    ComboBox1.Width = 90
    ComboBox1.ListWidth = 90

    'Initialize CommandButton1
    CommandButton1.Left = 230
    CommandButton1.Top = 36
    CommandButton1.Height = 120
    CommandButton1.Width = 120

    'Note: Be sure to refer to have set the CommandButton1 to a bitmap file
      'Note: that is present on your system
    CommandButton1.PicturePosition = ComboBox1.Value
End Sub

Sub ComboBox1_Click()
    Select Case ComboBox1.Value
    Case 0  'Left Top
        CommandButton1.Caption = "Left Top"
        CommandButton1.PicturePosition = 0

    Case 1  'Left Center
        CommandButton1.Caption = "Left Center"
        CommandButton1.PicturePosition = 1

    Case 2  'Left Bottom
        CommandButton1.Caption = "Left Bottom"
        CommandButton1.PicturePosition = 2

    Case 3  'Right Top
        CommandButton1.Caption = "Right Top"
        CommandButton1.PicturePosition = 3

    Case 4  'Right Center
        CommandButton1.Caption = "Right Center"
        CommandButton1.PicturePosition = 4

    Case 5  'Right Bottom
        CommandButton1.Caption = "Right Bottom"
        CommandButton1.PicturePosition = 5

    Case 6  'Above Left
        CommandButton1.Caption = "Above Left"
        CommandButton1.PicturePosition = 6

    Case 7  'Above Center
        CommandButton1.Caption = "Above Center"
        CommandButton1.PicturePosition = 7

    Case 8  'Above Right
        CommandButton1.Caption = "Above Right"
        CommandButton1.PicturePosition = 8

    Case 9  'Below Left
        CommandButton1.Caption = "Below Left"
        CommandButton1.PicturePosition = 9

    Case 10 'Below Center
        CommandButton1.Caption = "Below Center"
        CommandButton1.PicturePosition = 10

    Case 11 'Below Right
        CommandButton1.Caption = "Below Right"
        CommandButton1.PicturePosition = 11

    Case 12 'Centered
        CommandButton1.Caption = "Centered"
        CommandButton1.PicturePosition = 12

    End Select

End Sub


Pmt function example

This example uses the Pmt function to return the payment for a loan over a fixed period. Given are the interest percentage rate per period (APR / 12), the total number of payments (TotPmts), the present value or principal of the loan (PVal), the future value of the loan (FVal), and a number that indicates whether the payment is due at the beginning or end of the payment period (PayType).

Pmt([APR] / 12, [TotPmts], -[PVal], [FVal], [PayType])


PPmt function example

This example uses the PPmt function to calculate how much of a payment for a specific period is principal when all the payments are of equal value. Given are the interest percentage rate per period (APR / 12), the payment period for which the principal portion is desired (Period), the total number of payments (TotPmts), the present value or principal of the loan (PVal), the future value of the loan (FVal), and a number that indicates whether the payment is due at the beginning or end of the payment period (PayType).

PPmt([APR] / 12, [Period], [TotPmts], -[PVal], [FVal], [PayType])


PV function example

In this example, the PV function returns the present value of an annuity given the expected annual percentage rate (APR), the total number of payments (TotPmts), the amount of each payment (YrIncome), the total future value of the investment (FVal), and a number that indicates whether each payment is made at the beginning or end of the payment period (PayType). Note that because YrIncome represents cash paid out from the annuity each year, it's a negative number.

PV([APR], [TotPmts], -[YrIncome], [FVal], [PayType])


Rate function example

This example uses the Rate function to calculate the interest rate of a loan given the total number of payments (TotPmts), the amount of the loan payment (Payment), the present value or principal of the loan (PVal), the future value of the loan (FVal), a number that indicates whether the payment is due at the beginning or end of the payment period (PayType), and an approximation of the expected interest rate (Guess).

(Rate([TotPmts], -[Payment], [PVal], [FVal], [PayType], [Guess]) * 12) * 100


Right function example

The following example returns four characters from the right side of the Subject field.

Subject field | Function returns
International Sales | ales
Marketing Strategy | tegy

Right([Subject], 4)


Rnd function example

The following example uses the Rnd function to display a field with a random integer value from 1 to 6.

Int((6 * Rnd) + 1)


ScrollBars, KeepScrollBarsVisible Properties Example

The following example uses the ScrollBars and the KeepScrollBarsVisible properties to add scroll bars to a page of a MultiPage and to a Frame. The user chooses an option button that, in turn, specifies a value for KeepScrollBarsVisible.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • A MultiPage named MultiPage1.
  • A Frame named Frame1.
  • Four OptionButton controls named OptionButton1 through OptionButton4.
Sub Item_Open()
    Set MultiPage1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("MultiPage1")
    Set Frame1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("Frame1")
    Set OptionButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("OptionButton1")
    Set OptionButton2 = Item.GetInspector.ModifiedFormPages("P.2").Controls("OptionButton2")
    Set OptionButton3 = Item.GetInspector.ModifiedFormPages("P.2").Controls("OptionButton3")
    Set OptionButton4 = Item.GetInspector.ModifiedFormPages("P.2").Controls("OptionButton4")

    MultiPage1.Pages(0).ScrollBars = 3    '3=fmScrollBarsBoth
    MultiPage1.Pages(0).KeepScrollBarsVisible = 0    '0=fmScrollBarsNone

    Frame1.ScrollBars = 3    '3=fmScrollBarsBoth
    Frame1.KeepScrollBarsVisible = 0    '0=fmScrollBarsNone

    OptionButton1.Caption = "No scroll bars"
    OptionButton1.Value = True
    OptionButton2.Caption = "Horizontal scroll bars"
    OptionButton3.Caption = "Vertical scroll bars"
    OptionButton4.Caption = "Both scroll bars"
End Sub

Sub OptionButton1_Click()
    Set MultiPage1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("MultiPage1")
    Set Frame1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("Frame1")

    MultiPage1.Pages(0).KeepScrollBarsVisible = 0    '0=fmScrollBarsNone
    Frame1.KeepScrollBarsVisible = 0    '0=fmScrollBarsNonefmScrollBarsNone
End Sub

Sub OptionButton2_Click()
    Set MultiPage1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("MultiPage1")
    Set Frame1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("Frame1")

    MultiPage1.Pages(0).KeepScrollBarsVisible = 1    '1=fmScrollBarsHorizontal
    Frame1.KeepScrollBarsVisible = 1    '1=fmScrollBarsHorizontal
End Sub

Sub OptionButton3_Click()
    Set MultiPage1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("MultiPage1")
    Set Frame1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("Frame1")

    MultiPage1.Pages(0).KeepScrollBarsVisible = 2    '2=fmScrollBarsVertical
    Frame1.KeepScrollBarsVisible = 2    '2=fmScrollBarsVertical
End Sub

Sub OptionButton4_Click()
    Set MultiPage1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("MultiPage1")
    Set Frame1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("Frame1")

    MultiPage1.Pages(0).KeepScrollBarsVisible = 3    '3=fmScrollBarsBoth
    Frame1.KeepScrollBarsVisible = 3    '3=fmScrollBarsBoth
End Sub


Second function example

The following example uses the Second function to return the second of the time of the Received field.

Second([Received])


Sgn function example

The following example returns the following values for the Angle field.

Angle field | Function returns
30 | 1
-45 | -1

Sgn([Angle])


Sin function example

The following example uses the Sin function to return the sine of the Angle field.

Sin([Angle])


SLN function example

This example uses the SLN function to return the straight-line depreciation of an asset for a single period given the asset's initial cost (InitCost), the salvage value at the end of the asset's useful life (SalvageVal), and the total life of the asset in years (LifeTime).

SLN([InitCost], [SalvageVal], [LifeTime])


Space function example

The following example uses the Space function to return 10 spaces between the values of the Sent and Received fields in a column.

[Sent] & Space(10) & [Received]


Sqr function example

This example returns the following values for the Angle field.

Angle field | Function returns
4 | 2
23 | 4.795831523313
0 | 0

Sqr([Angle])


StrComp function example

The following example compares the value of the File As field with the value of a combination of the First Name and Last Name fields.

StrComp([File As], [Last Name] & ", " & [First Name], 1)


Str function example

The following example uses the Str function to return a string representation of the Number field. When a number is converted to a string, a leading space is always reserved for its sign.

Number field | Function returns
459 | " 459"
-459.65 | "-459.65"
459.001 | " 459.001"

Str([Number])


String function example

The following examples use the String function to return repeating character strings of the length specified.

Function | Returns
String(5, "*") | *****
String(5, 42) | *****
String(10, "ABC") | AAAAAAAAAA


Style Property Example for ComboBox

The following example uses the Style property to change the effect of typing in the text area of a ComboBox. The user chooses a style by selecting an OptionButton control and then types into the ComboBox to select an item. When Style is StyleDropDownList, the user must choose an item from the drop-down list. When Style is StyleDropDownCombo, the user can type into the text area to specify an item in the drop-down list.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • Two OptionButton controls named OptionButton1 and OptionButton2.
  • A ComboBox named ComboBox1.
Sub OptionButton1_Click()
    Set ComboBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ComboBox1")
    ComboBox1.Style = 0        '0=fmStyleDropDownCombo
End Sub

Sub OptionButton2_Click()
    Set ComboBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ComboBox1")
    ComboBox1.Style = 2        '2=fmStyleDropDownList
End Sub

Sub Item_Open()
    Set ComboBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ComboBox1")
    Set OptionButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("OptionButton1")
    Set OptionButton2 = Item.GetInspector.ModifiedFormPages("P.2").Controls("OptionButton2")

    For i = 1 To 10
        ComboBox1.AddItem "Choice " & i
    Next

    OptionButton1.Caption = "Select like ComboBox"
    OptionButton1.Value = True
    ComboBox1.Style = 0        '0=fmStyleDropDownCombo

    OptionButton2.Caption = "Select like ListBox"
End Sub


Style Property Example for MultiPage and TabStrip

The following example uses the Style property to specify the appearance of the tabs in MultiPage and TabStrip. This example also demonstrates using a Label. The user chooses a style by selecting an OptionButton.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • A Label named Label1.
  • Three OptionButton controls named OptionButton1 through OptionButton3.
  • A MultiPage named MultiPage1.
  • A TabStrip named TabStrip1.
  • Any control inside the TabStrip.
  • Any control in each page of the MultiPage.
Sub OptionButton1_Click()
    Set MultiPage1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("MultiPage1")
    Set TabStrip1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TabStrip1")
    MultiPage1.Style = 0        '0=fmTabStyleTabs
    TabStrip1.Style = 0        '0=fmTabStyleTabs
End Sub

Sub OptionButton2_Click()
    'Note that the page borders are invisible
    Set MultiPage1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("MultiPage1")
    Set TabStrip1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TabStrip1")
    MultiPage1.Style = 1        '1=fmTabStyleButtons
    TabStrip1.Style = 1        '1=fmTabStyleButtons
End Sub

Sub OptionButton3_Click()
    'Note that the page borders are invisible and
    'the page body begins where the tabs normally appear.
    Set MultiPage1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("MultiPage1")
    Set TabStrip1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TabStrip1")
    MultiPage1.Style = 2        '2=fmTabStyleNone
    TabStrip1.Style = 2        '2=fmTabStyleNone
End Sub

Sub Item_Open()
    Set Label1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("Label1")
    Set OptionButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("OptionButton1")
    Set OptionButton2 = Item.GetInspector.ModifiedFormPages("P.2").Controls("OptionButton2")
    Set OptionButton3 = Item.GetInspector.ModifiedFormPages("P.2").Controls("OptionButton3")
    Set MultiPage1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("MultiPage1")
    Set TabStrip1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TabStrip1")

    Label1.Caption = "Page/Tab Style"
    OptionButton1.Caption = "Tabs"
    OptionButton1.Value = True
    MultiPage1.Style = 0        '0=fmTabStyleTabs
    TabStrip1.Style = 0        '0=fmTabStyleTabs

    OptionButton2.Caption = "Buttons"
    OptionButton3.Caption = "No Tabs or Buttons"
End Sub


Switch function example

The following example uses the Switch function to return the name of a language that matches the name of the Business Address City field.

Business Address City field | Function returns
London | English
Paris | French

Switch([Business Address City] = "London",
"English", [Business Address City]= "Paris", "French")


SYD function example

By using the sum-of-years digits method, this example illustrates the use of the SYD function to return the depreciation of an asset for a specified period given the asset's initial cost (InitCost), the salvage value at the end of the asset's useful life (SalvageVal), and the total life of the asset in years (LifeTime). The period for which the depreciation is calculated is DepYear, also in years.

SYD([InitCost], [SalvageVal], [LifeTime], [DepYear])


TabFixedHeight, TabFixedWidth Properties Example

The following example uses the TabFixedHeight and TabFixedWidth properties to set the size of the tabs used in MultiPage and TabStrip. The user clicks the SpinButton controls to adjust the height and width of the tabs within the MultiPage and TabStrip.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • A MultiPage named MultiPage1.
  • A TabStrip named TabStrip1.
  • A Label named Label1 for the width control.
  • A SpinButton named SpinButton1 for the width control that is bound to a custom number field named SpinButtonWidth.
  • A TextBox named TextBox1 for the width control.
  • A Label named Label2 for the height control.
  • A SpinButton named SpinButton2 for the height control that is bound to a custom number field named SpinButtonHeight.
  • A TextBox named TextBox2 for the height control.
Sub UpdateTabWidth()
    Set TextBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TextBox1")
    Set SpinButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("SpinButton1")
    Set TabStrip1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TabStrip1")
    Set MultiPage1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("MultiPage1")

    TextBox1.Text = SpinButton1.Value
    TabStrip1.TabFixedWidth = SpinButton1.Value
    MultiPage1.TabFixedWidth = SpinButton1.Value
End Sub

Sub UpdateTabHeight()
    Set TextBox2 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TextBox2")
    Set SpinButton2 = Item.GetInspector.ModifiedFormPages("P.2").Controls("SpinButton2")
    Set TabStrip1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TabStrip1")
    Set MultiPage1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("MultiPage1")

    TextBox2.Text = SpinButton2.Value
    TabStrip1.TabFixedHeight = SpinButton2.Value
    MultiPage1.TabFixedHeight = SpinButton2.Value
End Sub

Sub Item_Open()
    Set TextBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TextBox1")
    Set TextBox2 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TextBox2")
    Set SpinButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("SpinButton1")
    Set SpinButton2 = Item.GetInspector.ModifiedFormPages("P.2").Controls("SpinButton2")
    Set TabStrip1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TabStrip1")
    Set MultiPage1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("MultiPage1")
    Set Label1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("Label1")
    Set Label2 = Item.GetInspector.ModifiedFormPages("P.2").Controls("Label2")

    MultiPage1.Style = 1        '1=fmTabStyleButtons

    Label1.Caption = "Tab Width"
    SpinButton1.Min = 0
    SpinButton1.Max = TabStrip1.Width / TabStrip1.Tabs.Count
    SpinButton1.Value = 0
    TextBox1.Locked = True

    UpdateTabWidth

    Label2.Caption = "Tab Height"
    SpinButton2.Min = 0
    SpinButton2.Max = TabStrip1.Height
    SpinButton2.Value = 0
    TextBox2.Locked = True

    UpdateTabHeight
End Sub

Sub Item_CustomPropertyChange(byval pname)
'msgbox pname
    If pname = "SpinButtonWidth" Then
        UpdateTabWidth
    ElseIf pname = "SpinButtonHeight" Then
        UpdateTabHeight
    End If
End Sub


TabIndex Property Example

The following example uses the TabIndex property to display and set the tab order for individual controls. The user can press TAB to reach the next control in the tab order and to display the TabIndex of that control. The user can also click on any control, except a TextBox or ScrollBar, to display its TabIndex. The user can change the TabIndex of a control by specifying a new index value in the TextBox and clicking CommandButton3. Changing the TabIndex for one control also updates the TabIndex for other controls in the Frame.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • A Label named Label1.
  • A TextBox named TextBox1.
  • A Frame named Frame1.
  • A TextBox in the Frame named TextBox2.
  • Two CommandButton controls in the Frame named CommandButton1 and CommandButton2.
  • A ScrollBar in the Frame named ScrollBar1.
  • A CommandButton (not in the Frame) named CommandButton3.
Sub MoveToFront()
    Set Frame1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("Frame1")
    Set TextBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TextBox1")

    Temp = Frame1.ActiveControl.TabIndex
    For i = 0 To Temp - 1
        Frame1.Controls.Item(i).TabIndex = i + 1
    Next

    Frame1.ActiveControl.TabIndex = 0
    TextBox1.Text = Frame1.ActiveControl.TabIndex
End Sub

Sub CommandButton3_Click()
    Set Frame1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("Frame1")
    Set TextBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TextBox1")

    If IsNumeric(TextBox1.Text) Then
        Temp = CInt(TextBox1.Text)

        If Temp >= Frame1.Controls.Count Or Temp < 0 Then
            'Entry out of range; move control to front of tab order
            MoveToFront
        ElseIf Temp > Frame1.ActiveControl.TabIndex Then
            'Move entry down the list
            For i = Frame1.ActiveControl.TabIndex + 1 To Temp
                Frame1.Controls.Item(i).TabIndex = i - 1
            Next
            Frame1.ActiveControl.TabIndex = Temp
            TextBox1.Text = Frame1.ActiveControl.TabIndex
        Else
            'Move Entry up the list
            For i = Frame1.ActiveControl.TabIndex - 1 To Temp
                Frame1.Controls.Item(i).TabIndex = i + 1
            Next
            Frame1.ActiveControl.TabIndex = Temp
            TextBox1.Text = Frame1.ActiveControl.TabIndex
        End If
    Else
        'Text entry; move control to front of tab order
        MoveToFront
    End If
End Sub

Sub Item_Open()
    Set Frame1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("Frame1")
    Set TextBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TextBox1")
    Set Label1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("Label1")
    Set CommandButton3 = Item.GetInspector.ModifiedFormPages("P.2").Controls("CommandButton3")

    Label1.Caption = "TabIndex"

    Frame1.Controls(0).SetFocus
    TextBox1.Text = Frame1.ActiveControl.TabIndex

    Frame1.Cycle = 2        '2=fmCycleCurrentForm

    CommandButton3.Caption = "Set TabIndex"
    CommandButton3.TakeFocusOnClick = False
End Sub

Sub CommandButton1_Click()
    Set Frame1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("Frame1")
    Set TextBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TextBox1")

    TextBox1.Text = Frame1.ActiveControl.TabIndex
End Sub

Sub CommandButton2_Click()
    Set Frame1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("Frame1")
    Set TextBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TextBox1")

    TextBox1.Text = Frame1.ActiveControl.TabIndex
End Sub


TabStop Property Example

The following example uses the TabStop property to control whether a user can press TAB to move the focus to a particular control. The user presses TAB to move the focus among the controls on the form, and then clicks the ToggleButton to change TabStop for CommandButton1. When TabStop is False, CommandButton1 will not receive the focus by using TAB.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • A CommandButton named CommandButton1.
  • A ToggleButton named ToggleButton1.
  • One or two other controls, such as an OptionButton or ListBox.
Sub CommandButton1_Click()
    MsgBox "Clicked CommandButton1."
End Sub

Sub ToggleButton1_Click()
    Dim CommandButton1
    Set ToggleButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ToggleButton1")
    Set CommandButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("CommandButton1")

    If ToggleButton1 = True Then
        CommandButton1.TabStop = True
        ToggleButton1.Caption = "TabStop On"
    Else
        CommandButton1.TabStop = False
        ToggleButton1.Caption = "TabStop Off"
    End If
End Sub

Sub Item_Open()
    Set ToggleButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ToggleButton1")
    Set CommandButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("CommandButton1")

    CommandButton1.Caption = "Show Message"

    ToggleButton1.Caption = "TabStop On"
    ToggleButton1.Value = True
    ToggleButton1.Width = 90
End Sub


Tag Property Example

The following example uses the Tag property to store additional information about each control on the UserForm. The user clicks a control and then clicks the CommandButton. The contents of Tag for the appropriate control are returned in the TextBox.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • A TextBox named TextBox1.
  • A CommandButton named CommandButton1.
  • A ScrollBar named ScrollBar1.
  • A ComboBox named ComboBox1.
  • A MultiPage named MultiPage1.
Sub CommandButton1_Click()
    Set TextBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TextBox1")
    Set MultiPage1= Item.GetInspector.ModifiedFormPages("P.2").Controls("MultiPage1")

    TextBox1.Text = Item.GetInspector.ModifiedFormPages("P.2").ActiveControl.Tag
End Sub

Sub Item_Open()
    Set TextBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TextBox1")
    Set CommandButton1= Item.GetInspector.ModifiedFormPages("P.2").Controls("CommandButton1")
    Set ComboBox1= Item.GetInspector.ModifiedFormPages("P.2").Controls("ComboBox1")
    Set ScrollBar1= Item.GetInspector.ModifiedFormPages("P.2").Controls("ScrollBar1")
    Set MultiPage1= Item.GetInspector.ModifiedFormPages("P.2").Controls("MultiPage1")

    TextBox1.Locked = True
    TextBox1.Tag = "Display area for Tag properties."
    TextBox1.AutoSize = True

    CommandButton1.Caption = "Show Tag of Current Control."
    CommandButton1.AutoSize = True
    CommandButton1.WordWrap = True
    CommandButton1.TakeFocusOnClick = False
    CommandButton1.Tag = "Shows tag of control that has the focus."

    ComboBox1.Style = fmStyleDropDownList
    ComboBox1.Tag = "ComboBox Style is that of a ListBox."

    ScrollBar1.Max = 100
    ScrollBar1.Min = -273
    ScrollBar1.Tag = "Max = " & ScrollBar1.Max & " , Min = " & ScrollBar1.Min

    MultiPage1.Pages.Add
    MultiPage1.Pages.Add
    MultiPage1.Tag = "This MultiPage has " & MultiPage1.Pages.Count & " pages."
End Sub


TakeFocusOnClick Property Example

The following example uses the TakeFocusOnClick property to control whether a CommandButton receives the focus when the user clicks on it. The user clicks a control other than CommandButton1 and then clicks CommandButton1. If TakeFocusOnClick is True, CommandButton1 receives the focus after it is clicked. The user can change the value of TakeFocusOnClick by clicking the ToggleButton.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • A CommandButton named CommandButton1.
  • A ToggleButton named ToggleButton1.
  • One or two other controls, such as an OptionButton or ListBox.
Sub CommandButton1_Click()
    MsgBox "Watch CommandButton1 to see if it takes the focus."
End Sub

Sub ToggleButton1_Click()
    Set ToggleButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ToggleButton1")
    Set CommandButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("CommandButton1")

    If ToggleButton1 = True Then
        CommandButton1.TakeFocusOnClick = True
        ToggleButton1.Caption = "TakeFocusOnClick On"
    Else
        CommandButton1.TakeFocusOnClick = False
        ToggleButton1.Caption = "TakeFocusOnClick Off"
    End If
End Sub

Sub Item_Open()
    Set ToggleButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ToggleButton1")
    Set CommandButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("CommandButton1")

    CommandButton1.Caption = "Show Message"

    ToggleButton1.Caption = "TakeFocusOnClick On"
    ToggleButton1.Value = True
    ToggleButton1.Width = 90
End Sub


Tan function example

The following example uses the Tan function to return the tangent of the numeric field Angle.

Tan([Angle])


TextColumn Property Example

The following example uses the TextColumn property to identify the column of data in a ListBox that supplies data for its Text property. This example sets the third column of the ListBox as the text column. As you select an entry from the ListBox, the value from the TextColumn will be displayed in the TextBox.

This example also demonstrates how to load a multicolumn ListBox using the AddItem method and the List property.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • A ListBox named ListBox1.
  • A TextBox named TextBox1.
Dim ListBox1
Dim TextBox1

Sub Item_Open()
    Set ListBox1 = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls("ListBox1")
    Set TextBox1 = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls("TextBox1")

    ListBox1.ColumnCount = 3

    ListBox1.AddItem "Row 1, Col 1"
    ListBox1.List(0, 1) = "Row 1, Col 2"
    ListBox1.List(0, 2) = "Row 1, Col 3"

    ListBox1.AddItem "Row 2, Col 1"
    ListBox1.List(1, 1) = "Row 2, Col 2"
    ListBox1.List(1, 2) = "Row 2, Col 3"

    ListBox1.AddItem "Row 3, Col 1"
    ListBox1.List(2, 1) = "Row 3, Col 2"
    ListBox1.List(2, 2) = "Row 3, Col 3"

    ListBox1.TextColumn = 3

End Sub

Sub ListBox1_Click()
    TextBox1.Text = ListBox1.Text
End Sub


Time function example

The following example uses the Time function to return the current system time.

Time( )


Timer function example

The following example uses the Timer function to return the seconds elapsed since midnight.

Timer( )


TimeSerial function example

The following example uses the TimeSerial function to return a time for the values specified in the Hour, Minute, and Second custom fields.

TimeSerial([Hour], [Minute], [Second])


TimeValue function example

The following example uses the TimeValue function to return a string entered in the Other field as a time.

TimeValue([Other])


TopIndex Property Example

The following example identifies the top item displayed in a ListBox and the item that has the focus within the ListBox. This example uses the TopIndex property to identify the item displayed at the top of the ListBox and the ListIndex property to identify the item that has the focus. The user selects an item in the ListBox. The displayed values of TopIndex and ListIndex are updated when the user selects an item or when the user clicks the CommandButton.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • A Label named Label1.
  • A TextBox named TextBox1.
  • A Label named Label2.
  • A TextBox named TextBox2.
  • A CommandButton named CommandButton1.
  • A ListBox named ListBox1 that is bound to the Subject field.
Sub CommandButton1_Click()
    Set ListBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ListBox1")
    Set TextBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TextBox1")
    Set TextBox2 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TextBox2")

    ListBox1.TopIndex = ListBox1.ListIndex
    TextBox1.Text = ListBox1.TopIndex
    TextBox2.Text = ListBox1.ListIndex
End Sub

Sub Item_PropertyChange(byval pname)
    if pname = "Subject" then
        Set TextBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TextBox1")
        Set TextBox2 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TextBox2")
        Set ListBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ListBox1")

        TextBox1.Text = ListBox1.TopIndex
        TextBox2.Text = ListBox1.ListIndex
    end if
End Sub

Sub Item_Open()
    Set ListBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ListBox1")
    Set CommandButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("CommandButton1")
    Set TextBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TextBox1")
    Set TextBox2 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TextBox2")
    Set Label1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("Label1")
    Set Label2 = Item.GetInspector.ModifiedFormPages("P.2").Controls("Label2")

    For i = 0 To 24
        ListBox1.AddItem "Choice " & (i + 1)
    Next
    ListBox1.Height = 66
    CommandButton1.Caption = "Move to top of list"
    CommandButton1.AutoSize = True
    CommandButton1.TakeFocusOnClick = False

    Label1.Caption = "Index of top item"
    TextBox1.Text = ListBox1.TopIndex

    Label2.Caption = "Index of current item"
    Label2.AutoSize = True
    Label2.WordWrap = False
    TextBox2.Text = ListBox1.ListIndex
End Sub


TripleState Property Example

The following example uses the TripleState property to allow Null as a legal value of a CheckBox and a ToggleButton. The user controls the value of TripleState through ToggleButton2. The user can set the value of a CheckBox or ToggleButton based on the value of TripleState. However, when a control is set to Null, no event is fired.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • A CheckBox named CheckBox1.
  • A ToggleButton named ToggleButton1.
  • A ToggleButton named ToggleButton2.
Sub Item_Open()
    Set CheckBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("CheckBox1")
    Set ToggleButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ToggleButton1")
    Set ToggleButton2 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ToggleButton2")

    CheckBox1.Caption = "Value is True"
    CheckBox1.Value = True
    CheckBox1.TripleState = False

    ToggleButton1.Caption = "Value is True"
    ToggleButton1.Value = True
    ToggleButton1.TripleState = False

    ToggleButton2.Value = False
    ToggleButton2.Caption = "Triple State Off"
End Sub

Sub ToggleButton2_Click()
    Set CheckBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("CheckBox1")
    Set ToggleButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ToggleButton1")
    Set ToggleButton2 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ToggleButton2")

    If ToggleButton2.Value = True Then
        ToggleButton2.Caption = "Triple State On"
        CheckBox1.TripleState = True
        ToggleButton1.TripleState = True
    Else
        ToggleButton2.Caption = "Triple State Off"
        CheckBox1.TripleState = False
        ToggleButton1.TripleState = False
    End If
End Sub

Sub CheckBox1_Click()
    Set CheckBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("CheckBox1")
    If IsNull(CheckBox1.Value) Then
        CheckBox1.Caption = "Value is Null"
    ElseIf CheckBox1.Value = False Then
        CheckBox1.Caption = "Value is False"
    ElseIf CheckBox1.Value = True Then
        CheckBox1.Caption = "Value is True"
    End If
End Sub

Sub ToggleButton1_Click()
    Set ToggleButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ToggleButton1")
    If IsNull(ToggleButton1.Value) Then
        ToggleButton1.Caption = "Value is Null"
    ElseIf ToggleButton1.Value = False Then
        ToggleButton1.Caption = "Value is False"
    ElseIf ToggleButton1.Value = True Then
        ToggleButton1.Caption = "Value is True"
    End If
End Sub


UCase function example

The following example returns uppercase values of the Subject field.

Subject field | Function returns
International Sales | INTERNATIONAL SALES
Marketing Strategy | MARKETING STRATEGY

UCase([Subject])


Val function example

The following example uses the Val function to return the numbers contained in the field String.

String field | Function returns
"2457" | 2457
"2 45 7" | 2457
"24 and 57" | 24

Val([String])


Value Property Example

The following example demonstrates the values that the different types of controls can have by displaying the Value property of a selected control. The user chooses a control by pressing TAB or by clicking on the control. Depending on the type of control, the user can also specify a value for the control by typing in the text area of the control, by clicking one or more times on the control, or by selecting an item, page, or tab within the control. The user can display the value of the selected control by clicking the appropriately labeled CommandButton.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • A CommandButton named CommandButton1.
  • A TextBox named TextBox1.
  • A CheckBox named CheckBox1.
  • A ComboBox named ComboBox1.
  • A CommandButton named CommandButton2.
  • A ListBox named ListBox1.
  • A MultiPage named MultiPage1.
  • Two OptionButton controls named OptionButton1 and OptionButton2.
  • A ScrollBar named ScrollBar1.
  • A SpinButton named SpinButton1.
  • A TabStrip named TabStrip1.
  • A TextBox named TextBox2.
  • A ToggleButton named ToggleButton1.
Sub CommandButton1_Click()
    Set TextBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TextBox1")
    Set Form = Item.GetInspector.ModifiedFormPages("P.2")
     TextBox1.Text = "Value of " & Form.ActiveControl.Name & " is " &     Form.ActiveControl.Value
End Sub

Sub Item_Open()
    Set CommandButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("CommandButton1")
    Set TextBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TextBox1")
    Set ComboBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ComboBox1")
    Set ListBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ListBox1")
    Set CheckBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("CheckBox1")
    Set ToggleButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ToggleButton1")
    Set TextBox2 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TextBox2")

    CommandButton1.Caption = "Get value of current control"
    CommandButton1.AutoSize = True
    CommandButton1.TakeFocusOnClick = False
    CommandButton1.TabStop = False

    TextBox1.AutoSize = True

    For i = 0 To 10
        ComboBox1.AddItem "Choice " & (i + 1)
        ListBox1.AddItem "Selection " & (100 - i)
    Next

    CheckBox1.TripleState = True
    ToggleButton1.TripleState = True

    TextBox2.Text = "Enter text here."
End Sub


Weekday function example

The following example uses the Weekday function to obtain the day of the week from the Received field.

Weekday([Received])


Year function example

The following example uses the Year function to return the year of the Received field.

Year([Received])


ZOrder Method Example

The following example sets the z-order of a TextBox, so the user can display the entire TextBox (by bringing it to the front of the z-order) or can place the TextBox behind other controls (by sending it to the back of the z-order).

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • Three TextBox controls named TextBox1 through TextBox3.
  • A ToggleButton named ToggleButton1.
Dim ToggleButton1
Dim TextBox1
Dim TextBox2
Dim TextBox3

Sub Item_Open()
Set TextBox1 = Item.GetInspector.ModifiedFormPages("P.2").TextBox1
Set TextBox2 = Item.GetInspector.ModifiedFormPages("P.2").TextBox2
Set TextBox3 = Item.GetInspector.ModifiedFormPages("P.2").TextBox3
Set ToggleButton1 = Item.GetInspector.ModifiedFormPages("P.2").ToggleButton1

'Set up text boxes to show z-order in the form
TextBox1.Text = "TextBox 1"
TextBox2.Text = "TextBox 2"
TextBox3.Text = "TextBox 3"

TextBox1.Height = 40
TextBox2.Height = 40
TextBox3.Height = 40

TextBox1.Width = 60
TextBox2.Width = 60
TextBox3.Width = 60

TextBox1.Left = 10
TextBox1.Top = 10

TextBox2.Left = 25      'Overlap TextBox2 on TextBox1
TextBox2.Top = 25

TextBox3.Left = 40      'Overlap TextBox3 on TextBox2, TextBox1
TextBox3.Top = 40

ToggleButton1.Value = False
ToggleButton1.Caption = "Bring TextBox2 to Front"
ToggleButton1.Left = 10
ToggleButton1.Top = 90
ToggleButton1.Width = 50
ToggleButton1.Height = 50

End Sub

Sub ToggleButton1_Click()
If ToggleButton1.Value = True Then
  TextBox2.ZOrder (fmTop)          'Place TextBox2 on Top of z-order

  'Update ToggleButton caption to identify next state
  ToggleButton1.Caption = "Send TextBox2 to back"
Else
    TextBox2.ZOrder (1)              'Place TextBox2 on Bottom of z-order

    'Update ToggleButton caption to identify next state
    ToggleButton1.Caption = "Bring TextBox2 to front"
End If
End Sub


Create an Outlook item

This procedure uses the Click event to call CreateItem to create and show an appointment when a user clicks CommandButton1.

In design mode:

  1. Using the Control Toolbox, place a CommandButton on your form.
  2. Open the Script Editor.

    How?

  3. Enter the following code, using the value from the table below to specify the type of item that you want to create.
    Sub CommandButton1_Click
    Application.CreateItem(1).Display
End Sub
Type of item | Has the value
MailItem | 0
AppointmentItem | 1
ContactItem | 2
TaskItem | 3
JournalItem | 4
NoteItem | 5
PostItem | 6
DistListItem | 7


Go to a line of code

  1. Open the Script Editor.

    How?

  2. On the Edit menu, click Go To.
  3. In the Line Number box, type in the number of the line of code to which you want to go.


How to use the Outlook object browser

To view the Outlook object browser:

1 Open a form in design mode.

2 In the Form menu, click View Code to view the Script Editor.

3 In the Script Editor, click Object Browser on the Script menu or press F2.

All of the available Outlook objects are listed in the Classes pane of the object browser in alphabetical order.

To view the members of an object, select the object in the Classes pane. The members of this object appear in alphabetical order in the Members of pane. The heading at the top of this pane will reflect the name of the object that you select. For example, if you select the AppointmentItem object in the Classes pane, the heading of the Members of pane will appear as Members of AppointmentItem.

The details pane shows the definition of the selected member. This text is read-only and cannot be copied and pasted into the Script Editor.

To insert an item from the object browser into the Script Editor:

1 In the Script Editor, position your cursor at the location for insertion.

2 Select the desired object in the Classes pane.

3 Select the desired member of this object in the Members of pane.

4 Click the Insert button.

Note The Insert button remains unavailable until a member of the object is selected.


How to use the Outlook script debugger

To use the script debugger, open a form in design mode.

To add VBScript to the form, on the Form menu, click on View Code. In the Script Editor window, add the necessary VBScript for your form.

For more information about adding VBScript to the form, click here

On the Form menu, click Run This Form.

While your form is in run mode, on the Tools menu, select Forms and click Script Debugger.

You can also use the Stop statement in code to launch the debugger.

Note If there is no VBScript for this form, the Script Debugger menu item will be unavailable.

The VBScript for this form will appear in a read-only window. You cannot change text in this window.

On the Help menu of the Microsoft Script Debugger, select Help Topics for more detailed information about:

  • Debugging scripts
  • Viewing source code
  • Controlling program execution
  • Viewing and changing values
  • Viewing and controlling program flow


Change the value of a field

To change the value of an Outlook field, use the property name of the associated standard field. For example, to change the value of the Subject field, use the following code.

Item.Subject = "New Subject"

To change the value of a custom field, use the following code to refer to a custom field.

Item.UserProperties.Find("MyProperty").Value = "New Value"


Use message boxes to return values

One way to isolate errors is to use a message box to display the value of a variable or property at a particular point in the coce. This code example shows the selection length returned from the SelLength property in a message box.

MsgBox Item.GetInspector.ModifiedFormPages("Test").Textbox1.SelLength


Use the PropertyChange event to test procedures

Perform the following steps to test simple procedures. Replace the code below with the code that you want to test. Each time a user changes the value of the Importance field, or any other default field, the code runs.

  1. Open the Script Editor.

    How?

  2. On the Script menu, click Event Handler.
  3. In the Events box, double-click PropertyChange.
  4. Add the following code in the event:

    MsgBox "This is my test procedure"

  5. On the Form menu, click Run This Form.
  6. Click the ! icon on the toolbar. The message box will appear.
  7. Click OK to close the message box.


Add a Click event for a control

  1. Open the Script Editor.

    How?

  2. For the control to which you want to add a Click event, add the following, where CommandButton1 is the name of the control.

    Sub CommandButton1_Click

    End Sub

  3. Enter the code that you want in the event.


Add an Outlook event

  1. Open the Script Editor.

    How?

  2. On the Script menu, click Event Handler.
  3. In the Insert Events Handler box, click the event that you want to use, and then click Add.


Use current user properties from the Microsoft Exchange Server global address list

In code, open an OLE messaging session and log on, and then use the following table to reference the property you want to use.

Set olemSession = Application.CreateObject("MAPI.Session")
ReturnCode = olemSession.Logon( Application.GetNameSpace("MAPI").CurrentUser, "", False, False, 0 )
myPage = Item.GetInspector.ModifiedFormPages("Message")
Set myUser = olemSession.CurrentUser
Item.UserProperties.Find("Name") = myUser.Name
Item.UserProperties.Find("Messaging Address") = myUser.Address
Item.UserProperties.Find("MAPI First Name") = myUser.Fields.item(&h3a06001e)
Address Book Property | Reference
PR_GIVEN_NAME | &h3a06001e
PR_INITIALS | &h3a0a001e
PR_SURNAME | &h3a11001e
PR_7BIT_DISPLAY_NAME | &h39ff001e
PR_STREET_ADDRESS | &h3a29001e
PR_LOCALITY | &h3a27001e
PR_STATE_OR_PROVINCE | &h3a28001e
PR_POSTAL_CODE | &h3a2a001e
PR_COUNTRY | &h3a26001e
PR_TITLE | &h3a17001e
PR_COMPANY_NAME | &h3a16001e
PR_DEPARTMENT_NAME | &h3a18001e
PR_OFFICE_LOCATION | &h3a19001e
PR_ASSISTANT | &h3a30001e
PR_BUSINESS_TELEPHONE_NUMBER | &h3a08001e


Reference the active user

Use GetNameSpace to return the Outlook NameSpace object from the Application object, and then use the CurrentUser property to return a Recipient object repesenting the active user, as shown in the following example.

Set myUser = Application.GetNameSpace("MAPI").CurrentUser


Put a list of fields and values in the message body

To add a list of fields and values in the body of an item, define a variable to contain the string, and then use Outlook properties that refer to the field you want to include. For example, to include the To field in the message body, use the following. Chr (13) is the return character.

MessageString = "This letter is sent to " & Item.To & chr(13)
MessageString = MessageString & "second line goes here"
Item.Body = MessageString