Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combobox. Allowing a blank entry

Status
Not open for further replies.

AndrewMozley

Programmer
Oct 15, 2005
621
GB
I have a form which allows me to examine and edit a table, Thistable. The table has fields This.code, This.desc and This.Supplier. This.supplier identifies a record in an associated table thattable, which has fields That.Account and That.suppname. However This.Supplier may be blank. In this case it does not reference any record in Thattable.

When I am editing or adding the records in Thistable, I want to display the value of This.supplier and the associated description, That.Suppname.

To do this I have a combo box on the form, cboSupp
So cboSupp.controlsource = Thistable.Supplier
cboSupp.Rowsourcetype = 6 (Fields)
cboSupp.RowSource = Thattable.Account,Suppname

This works well and allows the Suppname to be shown corresponding to This.supplier
However (when I am editing Thistable) I would like to be able to enter a blank value into This.supplier. In this case the Suppname field would be blank.

Is there a way of doing this with a combo box? I suppose I could make the RowsourceType = 5 (array), and populate that array in the Init() method of the form, with one blank pair of values, and then fill the rest with That.account, that.suppname.

But the table Thattable is quite large, and I feel that there must be a better way. Grateful for suggestions.
 
You can create a CURSOR and add blank row in it:
Code:
SELECT Account,Suppname;
FROM Thattable;
UNION;
SELECT "", "";
FROM Thattable;
INTO CURSOR cboThattable


cboSupp.Rowsourcetype = 6 (Fields)
cboSupp.RowSource = cboThattable.Account,Suppname

Borislav Borissov
VFP9 SP2, SQL Server
 
Andrew,

Do you by any chance still have a copy of my LookupComboSpecial class (in my Controls.VCX). It does exactly what you want, with the added feature that you can set the "blank" value to any string you line (e.g " --- none --- ").

In fact, it uses an approach similar to that suggested above my Borislav, that is, it generates an internal cursor with an extra "blank" record.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top