Database development and training for Birmingham and the midlands
Specialists in Microsoft Access and Visual Foxpro database training and development
I am happy to hear from existing clients but I am taking no new calls.
Using a cursor in a listbox
This piece of SQL code:
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 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