How do you make a combo box able to accept hand entered values, when my users hand enter a value it does not show after they save, it shows on the form but after they save it is gone.
There is no "magic" here - you have to add it to the underlying data source. How, depends on what the RowSourceType and Rowsource properties are set to.
What's your ControlSource property set to? If Table.Field is your ControlSource, then in the lostfocus() you'll need to do a This.Requery() to effectively add this new value to the list. If it isn't Table.Field, then you'll need to do a REPLACE into the table - maybe in the lostfocus() method AND do the This.Requery().
oh I dont want it to appear there all the time, i just want the user to be able to enter one by hand and have it save and show , not be a perminant option.
I guess I'm confused then - using the Fields variant, it only displays all the values in use in the table (it doesn't even automatically elimate the duplicates!), so perhaps you need to consider using a different RowSourceType (an Array?).
Permitting the user to enter an item that isn't in the list defeats the purpose of using a combo box in the first place. Having said that, I realize there may be occasions where this sort of functionality is required. For example, let's suppose a particular field in a table is usually populated from a set of standard selections. However, occasionally none of the standard selections are suitable and the end user needs to enter something that is not in the list. Clearly, if the non-standard items were regularly added to the underlying lookup table, the table would grow quickly with seldom used entries. In this instance, the field binding to the combo box must contain the description of the item in the lookup table and not its key value. Obviously, if we allow the field to be bound to items that are not in the list, we must store the information in this non-normalized manner. The only place to "look up" such ad hoc items is in the bound field itself!
The easiest way to implement what you are trying to do is to create a custom combo class and add a custome cControlSource property. This code in the combo's Init():
IF DODEFAULT()
WITH This
.cControlSource = .ControlSource
.ControlSource = ''
ENDWITH
ENDIF
Add a custom method called RefreshDisplayValue() and called this method from the combo's Refresh and GotFocus methods to update its DisplayValue with the value of the field to which it is bound. This code in RefreshDisplayValue() :
LOCAL lcControlSource
WITH This
IF ! EMPTY( .cControlSource )
lcControlSource = .cControlSource
.DisplayValue = &lcControlSource
ENDIF
ENDWITH
Finally, add a custom method called UpdateControlSource() and call it from the combo's Valid to (you guessed it) update its control source from its DisplayValue:
LOCAL lcAlias, lcControlSource
WITH This
IF ! EMPTY( .cControlSource )
lcAlias = JUSTSTEM( .cControlSource )
IF UPPER( ALLTRIM( lcAlias ) ) = 'THISFORM'
lcControlSource = .cControlSource
STORE .DisplayValue TO &lcControlSource
ELSE
REPLACE ( .cControlSource ) WITH .DisplayValue IN ( lcAlias )
ENDIF
ENDIF
ENDWITH
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.