Sign in with Microsoft
Sign in or create an account.
Hello,
Select a different account.
You have multiple accounts
Choose the account you want to sign in with.

Summary

Microsoft 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:

  1. 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 aTitle
  2. Add the customer table from the \Data directory to the Data Environment of the form. You can find the \Data directory 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\Data
  3. Place a text box on the form, and set its ControlSource property to:

          Customer.Contact
  4. Place a combo box on the form. Set its RowSource property to aTitle and its RowSourceType property to 5 - Array.

  5. In the InteractiveChange procedure, 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
  6. In the LostFocus procedure, 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=""
  7. Add a command button to the form, and type the following code into its
    Click event procedure:

          SKIP
    ThisForm.Combo1.DisplayValue=Customer.Contact
    ThisForm.Refresh
  8. Add another command button to the form, and place the following code in its Click event procedure:

          SKIP -1
    ThisForm.Combo1.DisplayValue=Customer.Contact
    ThisForm.Refresh
  9. Save 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.

References

For more information, click the following article number to view the article in the Microsoft Knowledge Base:

139769 How to add a new value to a list of values in a combo box

Need more help?

Want more options?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.

Was this information helpful?

What affected your experience?
By pressing submit, your feedback will be used to improve Microsoft products and services. Your IT admin will be able to collect this data. Privacy Statement.

Thank you for your feedback!

×