ComboBox - Is it in list?

S

Stu

ComboBox, LimitToList = No. What is the best way to see if the user entered
a value NOT on the list? (I see the NotInList event doesn't fire when
LimitToList = No.)
 
P

Piet Linden

ComboBox, LimitToList = No.  What is the best way to see if the user entered
a value NOT on the list?  (I see the NotInList event doesn't fire when
LimitToList = No.)

Weird. Post your code for the NotInList event...
 
D

Dirk Goldgar

Stu said:
ComboBox, LimitToList = No. What is the best way to see if the user
entered
a value NOT on the list? (I see the NotInList event doesn't fire when
LimitToList = No.)


When the current value of the combo box is not in the list, the control's
ListIndex property = -1. So:

If Me.cboMyCombo.ListIndex = -1 Then
' This value is not in the list.
End If
 
F

fredg

ComboBox, LimitToList = No. What is the best way to see if the user entered
a value NOT on the list? (I see the NotInList event doesn't fire when
LimitToList = No.)

Change LimitToList to Yes.
Access will generate a message.
Use the NotInList event to then add the value to the list or not, as
you wish. Search Groups.Google.com for various coding to add a value
to the list.
 
S

Stu

Thanks, Dirk.

Dirk Goldgar said:
When the current value of the combo box is not in the list, the control's
ListIndex property = -1. So:

If Me.cboMyCombo.ListIndex = -1 Then
' This value is not in the list.
End If


--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
F

FrozenJackal

Try this in the controls NotInList event.

Private Sub InsertControlName_NotInList(NewData As String, Response As
Integer)
Dim Db As DAO.Database
Dim rs As DAO.Recordset
Dim Msg As String

Msg = "'" & NewData & "' is not in the List." & vbCr & vbCr
Msg = Msg & "Whould you like to add it now?."
If MsgBox(Msg, vbQuestion + vbYesNo) = vbNo Then
Response = acDataErrContinue
MsgBox "Please select an Item from the list provided."
Else
Set Db = CurrentDb
Set rs = Db.OpenRecordset("InsertTableName", dbOpenDynaset)

rs.AddNew
rs![InsertFieldName] = NewData
rs.Update
Response = acDataErrAdded

End If
End Sub
 
T

TinMan

After going through different problems i found this one fille in the blanks
and problem solved thank you Frozen Jack for the simplicity.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top