This tech tip shows how to display the values from a field for a selection records returned by a query in a combo box.
Suppose you have the following interface and you want to display the detail of one specific invoice for the current customer. Notice the Combo box in the upper left of the form. It has been assigned a default value of the invoice number of one of the invoices belonging to this customer.
Clicking on the combo box displays a list of all the invoice numbers of invoices belonging to this customer.
Below you see the combo box with the user selected invoice number displayed in the combo box enterable area:
When the user tabs out of the combo box enterable area, the specified invoice is displayed:
This was implemented as follows:
- Place a combo box on the form.
- Specify the combo box variable name. Here, aLInvoiceNbs was used.
- Specify the combo box data type. Here, numeric was used because the source field is a Long Integer data type.
- Turn on the following events for the combo box object: On Load, On Data Change. Code assigned to the On Load event will initialize the combo box. Code assigned to the On Data Change event will execute when the user tabs out of the combo box enterable area, if they have changed the data in that area by typing or selecting a value form the combo box pop-up list.
- Turn off all other events.
- Place the following code in the object method of the combo box object:
: (Form event= )
`Search for invoices for the current customer
`Load the invoice numbers into an array
SELECTION TO ARRAY([Invoices]InvoiceNo;aLInvoiceNbs)
`Sort the array of invoice numbers ascending
`Assign the value in the first element of the array to be the default value
`displayed in the enterable area of the combo box.
`When the user tabs out of the enterable area of the combo box.
: (Form event= )
`Find and load the record selected by the user
`Display the user selected record
- Notice that the array and the combo box must have the same name for the contents of the array to display in the combo box.