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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Distinguisting between keyed-in value and list value in a ComboBox...

Status
Not open for further replies.

hoialmen

MIS
Dec 10, 2001
53
US
HI all!

I have a form that has a ComboBox that gets its list values from a table. I've set the box up to allow users to key a value into the box if the value they are looking for doesn't appear in the list. Now, my question is: Is there an event function that can distinguish between a value that was keyed in vs. a value that was selected from the ComboBox list? The reason I need to do this is because I would like to run 2 different sub functions depending on whether or not the user keyed in a new value.

Any thoughts will be greatly appreciated.

Thanks!

Nate
 
Hi

Sure is, see the NotInList event

Not you must have limit to list set to true for it to fire

Code below curtesy of Access Help, I think explains what you need to do

The following example uses the NotInList event to add an item to a combo box.
To try this example, create a combo box called Colors on a form. Set the combo box's LimitToList property to Yes. To populate the combo box, set the combo box's RowSourceType property to Value List, and supply a list of values separated by semicolons as the setting for the RowSource property. For example, you might supply the following values as the setting for this property: Red; Green; Blue.

Next add the following event procedure to the form. Switch to Form view and enter a new value in the text portion of the combo box.

Private Sub Colors_NotInList(NewData As String, _
Response As Integer)
Dim ctl As Control

' Return Control object that points to combo box.
Set ctl = Me!Colors
' Prompt user to verify they wish to add new value.
If MsgBox("Value is not in list. Add it?", vbOKCancel) = vbOK Then
' Set Response argument to indicate that data is being added.
Response = acDataErrAdded
' Add string in NewData argument to row source.
ctl.RowSource = ctl.RowSource & ";" & NewData

Else
' If user chooses Cancel, suppress error message and undo changes.
Response = acDataErrContinue
ctl.Undo
End If
End Sub Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
UK
kenneth.reaySPAMNOT@talk21.com
remove SPAMNOT to use
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top