Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This article describes how to input data that may not be contained in the ComboBox control drop-down list and then change a field value in a table with the value that was entered in the combo box.
Original product version: Visual FoxPro
Original KB number: 140652
Summary
Visual FoxPro lets you use combo boxes in forms to select or input data within the form. Combo boxes let data be derived from the following sources:
- Value
- Alias
- SQL statements
- Queries
- Arrays
- Fields
- Files
- Structures
- Popups
This article describes how to input information that may not be contained in the ComboBox control drop-down list and then change a field value in a table with the value that is entered in the combo box.
More information
To input data into a ComboBox control and then store it to a field in a table if the value has changed, follow these steps:
Create a new form, and place the following code in its Load event procedure:
PUBLIC ARRAY aTitle(1) SELECT DISTINCT(customer.contact) FROM customer ; INTO ARRAY aTitleAdd the customer table from the
\Datadirectory to the Data Environment of the form. You can find the\Datadirectory in one of the following locations:Visual FoxPro 3.x: VFP\Samples\Mainsamp Visual FoxPro 5.x: VFP\Samples Visual FoxPro 6.0: \MSDN98\98VS\1033\Samples Visual FoxPro 7.0,8.0,9.0: \Samples\DataPlace a text box on the form, and set its
ControlSourceproperty to:Customer.ContactPlace a combo box on the form. Set its
RowSourceproperty to aTitle and itsRowSourceTypeproperty to 5-Array.In the
InteractiveChangeprocedure, type the following lines of code:IF Customer.Contact != Thisform.combo1.DisplayValue REPLACE Customer.Contact WITH Thisform.combo1.DisplayValue Thisform.Text1.Refresh SELECT DISTINCT(customer.contact) FROM customer ; INTO ARRAY aTitle ENDIFIn the
LostFocusprocedure, type the following lines of code:IF Customer.Contact != Thisform.combo1.DisplayValue REPLACE Customer.Contact WITH Thisform.combo1.DisplayValue Thisform.Text1.Refresh SELECT DISTINCT(customer.contact) FROM customer ; INTO ARRAY aTitle ENDIF thisform.combo1.displayvalue=""Add a command button to the form, and type the following code into its
Clickevent procedure:SKIP ThisForm.Combo1.DisplayValue=Customer.Contact ThisForm.RefreshAdd another command button to the form, and place the following code in its
Clickevent procedure:SKIP -1 ThisForm.Combo1.DisplayValue=Customer.Contact ThisForm.RefreshSave and run the form. Change the value in the combo box, and skip through the table using the command buttons. Close the form, and browse the Customer table. Look at the Contact field. The changes entered in the combo box will be reflected in the field.