Allowing Specific Actions
Frequently, you want to make it possible for users to take specific actions that have nothing to do with manipulating values. For example, you can make it possible for a user to close a form, open another form, move through a table, save or cancel edits, run a report or query, jump to an address of a destination on the Internet or an intranet, or any number of other actions.
Using Command Buttons and Command Button Groups
One of the most common places to put the code for specific actions is the Click event of a command button.
Making a Command Button the Default Choice
Set the Default property to true (.T.) to make the command button the default choice. The default choice has a thicker border than other command buttons. If a command button is the default choice, when the user presses ENTER, the Click event of the command button executes.
Note If the selected object on a form is an edit box or a grid, the code associated with the Click event of the default choice is not executed when the user presses ENTER. Pressing ENTER in an edit box adds a carriage return and line feed to the value in the edit box. Pressing ENTER in a grid selects an adjacent field. To execute the Click event of the default button, press CTRL+ENTER.
Common Command Button Properties
The following command button properties are commonly set at design time.
Property | Description |
---|---|
Cancel | Specifies that the code associated with the Click event of the command button executes when a user presses ESC. |
Caption | Text displayed on the button. |
DisabledPicture | The .bmp file displayed when the button is disabled. |
DownPicture | The .bmp file displayed when the button is pressed. |
Enabled | Whether the button can be chosen. |
Picture | The .bmp file displayed on the button. |
You also can include command buttons in a group so that you can manipulate them individually or as a group.
Managing Command Button Choices at the Group Level
If you want to work with a single method procedure for all the code for the Click events of command buttons in a group, you can attach the code to the Click event of the command button group. The Value property of the command button group indicates which of the buttons was clicked, as demonstrated in the following code example:
DO CASE
CASE THIS.Value = 1
WAIT WINDOW "You clicked " + THIS.cmdCommand1.Caption NOWAIT
* do some action
CASE THIS.Value = 2
WAIT WINDOW "You clicked " + THIS.cmdCommand2.Caption NOWAIT
* do some other action
CASE THIS.Value = 3
WAIT WINDOW "You clicked " + THIS.cmdCommand3.Caption NOWAIT
* do a third action
ENDCASE
Note If the user clicks in the command button group but not on a particular button, the Value property still reflects the last command button that was selected. If you have written code for the Click event of a particular button in the group, that code is executed rather than the group Click event code when the user chooses that button.
Common Command Button Group Properties
The following command button group properties are commonly set at design time.
Property | Description |
---|---|
ButtonCount | Number of command buttons in the group. |
BackStyle | Whether the command button group has a transparent or opaque background. A transparent background appears to be the same color that the underlying object, usually the form or a page, is. |
Using the Hyperlink Object
You can use the Hyperlink object to jump to an address of a destination on the Internet or an intranet. The Hyperlink object can be used to start a hyperlink aware application, typically an Internet browser such as the Microsoft Internet Explorer, and open the page specified in the address. The Hyperlink NavigateTo( ) method makes it possible for you to specify the address of the destination that you jump to.
For example, to navigate to the Microsoft Internet site on the World Wide Web from a form, first add the Hyperlink control to the form. Add a command button to the form, and then add the following code to the Click event for the command button:
THISFORM.Hyperlink1.NavigateTo('www.microsoft.com')
When the form is run, you can click the command button to jump to the Microsoft Web site.
See Also
Accepting Numeric Input in a Given Range | Performing Specific Actions at Given Intervals | Using Controls | Controls and Objects | Displaying Information