Using a cursor in a listbox

Using a cursor as the source for a FoxPro combo box This piece of SQL code:

Select Cust_ID ;
   From customer ;
   Into Cursor csrCustID ;
   Order By cust_ID

creates a cursor named csrCustID which holds the customer ID values from the customer table. You might want to use this cursor as the source of the rows in a combo box or list so that the user can select a customer, it's just a matter of choosing 2-Alias as the RowSourceType and setting the cursor as the RowSource of the control.

This technique is quick and simple and ensures that the combo box is always filled with the most up-to-date information. The only point to watch for is to make sure that you create the cursor in the Load event of the form rather than in the Init event. The form Load happens before the Init of all the controls whereas the form Init happens afterwards. The RowSource has to exist before the control can initialise itself so it must be done in the Load event. The cursor needs the Customer table so it's sensible to open that in the Load event too. You can close the Customer table as soon as the cursor has been created and close the cursor in the form Unload event. Use the Use command each time

Use In csrCustId
Use In Customer

MS Access technical tips

Visual FoxPro technical tips

General Tips

 

More tips from Alvechurch Data

Scope of a FoxPro command

Scope of a FoxPro command

Using While and For to control the scope of a FoxPro command

Read More

Full outer join in Access

Creating a full outer join in Access SQL

Read More

Types of SQL join

Types of join in a SQL query

Read More

FoxPro cursors

FoxPro cursors

Using cursors in FoxPro

Read More

American date formats used by Access SQL

Microsoft Access uses an American date format in SQL commands

Read More