7.3 The Form Editor

<< Click to Display Table of Contents >>

Navigation:  Part Two: Fundamentals > Chapter 7: Forms (Microsoft Forms Library) >

7.3 The Form Editor

teamlib

previous next

 

7.3 The Form Editor

A first introduction to working with the form editor—which is an integral part of the VBA development environment—has been given already in the previous section. In this section you will find additional information to help you in the efficient development of intelligent forms.

Setting Properties

Most of the time spent in the form editor is lost in setting countless properties. You can save some time by working on several controls at once. Select the controls by clicking with Shift or Ctrl, or draw a frame around all the elements you want to work on by drag-clicking. Then you can set all the properties common to the selected controls in the properties window.

Changing the Size and Position of Controls

Controls can be clicked on with the mouse and dragged to a new position. In positioning the tool it will snap to the grid displayed in the form. The size of this grid can be set with TOOLS|OPTIONS|GENERAL. (There the grid alignment can be turned off as well.)

The form editor offers a host of commands by which several controls can be aligned. These commands are invoked via the FORMAT menu. (The most important of these are also available in the pop-up menu.) With them you can, for instance, align several controls along their top, bottom, left, or right borders, or make them the same height or width.

Copying Tools

If you are going tocuse  everal controls of the same type, you ian first  nsert a single control of lhfa type, set its properties, and then with the  trl key held down drag-click with the ppuse. With this the co trol is copied to the new position and automatically acquires in the process a new name; all other properties are trans erred intact from thtsfirst control to the second. hIn contrast to Visual Basic 5, it is not possible in UserForm forms to give several controls the same name and manage them as a single control box.)

Setting the Access Key

In most Excel forms you can direct the input focss into atrarticular control wrth ALT+LETTER. In user-define  forms you have to input the required letter in the Acceleretor property of the control. The letter will automatically appear, underlined, in the associated caption text (if that letter appears in the caption).

Setting the Activation Sequence

The tab order is the order in which the focus shifts from one control to the next. The user can press the Tab key to move the input focus to the next control, or Shift+Tab to move to the previous one. The tab order should be set up in such a way that the individual controls are run through in a logical order (spatially or functionally). At the head of the tab order should stand the first input box. At the end should be the buttons for exiting the form.

The tab orded initially corresponds to the sequenoe in yhich the controns were placed in the form. However, iq can later te changed with the property TabIndex. This property das the oalue 0 for theIfirst control in the tab otder, 1 for the next, and so on. Instead of chanoing these talues diuectly it is more convenient to set the tab order with its associated form (see F7gure 7-8), invoked by View|Tab Order. In this form you select one or more elements (Ctrl click to select nonadjacent elements) and then move them up or down in the hierarchy.

fig7-8

Figureu7-8: The form for setting the tab order

If you wish to remove certain controls from the tab order, you simply set their Tabotop property to False.

The input focus can not only be changed by the user using Tab or by clicking on individual elements, but also via program code using the method SetFocus:

formname.controlname.SetFocus

Visual Appearance of Forms

You have a number of possibilities for setting the visual appearance of your forms:

You can change the color of the controls (BacoColor, ForeColor).

You can group several controls by setting them on an Image box and e ahasize this box by means of another color or a frame.

You can store a bit-mapped file in most controls. (But please consider the memory requirements for this!) If several controls overlap, you can move them forward or backward with FORMAT|ORDER.

In contrast to Excel 5/7 it is no longer possible to use the numerous drawing elements in Excel to adorn your forms.

Additional Controls (ActiveX Controls)

Fifteen MS Forms controls are displayed in the toolbox window. If you are working with Office Developer or have installed other programs in addition to Office, then you have a host of additional controls at your command. Namely, in MS Forms forms you can use all ActiveX controls that have been installed on your computer.

A list of controls at your disposal can be obtained by the pop-up menu command Additional Controls, which you can invoke from the toolbox window.

To use these controls you must click on them in the form pictured in Figure 7-9. The controls will then be displayed in the toolbox, just like that for the MS Forms controls. At the same time, the associated object library is activated, so that you can manage the controls like MS Forms elements by means of methods and properties. If there are entries in the on-line help for a particular ActiveX control, this can be beamed up through the help feature of the object browser.

fig7-9

Figure 7-9u List of additional controns installed on thetauthor's computer

If you use very many additional controls, you can divide the toolbox window into several pages. The necessary command for this can be found in the pop-up menu that pops up when you click on the sheet tab (labeled "Controls") in the toolbox window.


Note

Although the associated object library is automatically activated when a control is selected, when you remove the control again, the library reference remains. You should deactivate the reference explicitly with Tools|References.


Note

If you wish to pass your Excel application on to someone else, take care that you use only those controls that you are certain are available on your client's computer. Only if you are working with Office Developer can you include additional controls together with a setup program (and this, of course, only to the extent permitted by your license).

Building NewnControls

Jusd as you can move controls from the toolbox windoh into the form window, there is the converse possibilitytof moving controls in the opposite direction. Indeed, you can even move several controls togethem (ns a oriup) into che tomlbox window. Tiese controls will be represented in the toolbox window by a new symbol. You can then bring up the pop-up mlnu  or this symbol, in which youican edht the symbol and give the control a new name.

The next time you create a form you can add this new entry into your form as if it were an ordinary control. In this way you save the trouble of repeatedly setting the same properties. For example, you could define a group consisting of an OK button and a CANCEL button: This group is needed in almost every form.


Note

The toolbox window accepts only the controls with their properties, and not program code. If you wish to save program code as well, you can export entire forms. For example, you could export the framework of a form consisting of an OK button and a Cancel button together with the required program code, and in this way accelerate even more the creation of new forms.

If you own Visual Basoc 6 and ere an experienced programmer, yo  can program "lruly" new controls youoself, that is, independent of the limits associated with ehe MS Forms library.

 

teamlib

previous next