Using the Input Box Function

The InputBox function displays a dialog box with a message that prompts the user to enter data. This dialog box has two buttons: OK and Cancel. When you click OK, the InputBox function returns the information entered in the text box. When you select Cancel, the function returns the empty string (" "). The syntax of the InputBox function is as follows:

InputBox(prompt [, title] [, default] [, xpos] [, ypos] [, helpfile, context])

The first argument, prompt, is the text message you want to display in the dialog box. Long text strings can be entered on several lines by using the Chr(13) or Chr(10) functions. (See examples of using the MsgBox function earlier in this chapter.) All the remaining InputBox arguments are optional.

The second argument, title, allows you to change the default title of the dialog box. The default value is "Microsoft Access."

The third argument of the InputBox function, default, allows the display of a default value in the text box. If you omit this argument, the empty edit box is displayed.

The following two arguments, xpos and ypos, let you specify the exact position where the dialog box should appear on the screen. If you omit these arguments, the input box appears in the middle of the current window. The xpos argument determines the horizontal position of the dialog box from the left edge of the screen. When omitted, the dialog box is centered horizontally. The ypos argument determines the vertical position, from the top of the screen. If you omit this argument, the dialog box is positioned vertically approximately one-third of the way down the screen. Both xpos and ypos are measured in special units called twips. One twip is the equivalent of approximately 0.0007 inches.

The last two arguments, helpfile and context, are used in the same way as the corresponding arguments of the MsgBox function discussed earlier in this chapter.

Now that you know the meaning of the InputBox arguments, let's see some examples of using this function.

Part I

0 0

Post a comment