Adding a value not in list

pfiroz

Registered User.
Local time
Today, 15:05
Joined
Jan 21, 2009
Messages
27
Hello all :)
I'm trying to figure out the best way to add a value that is not in a drop down combo list. After doing some searching online, I found this code:
Code:
Private Sub Trait_NotInList(NewData As String, Response As Integer)
If MsgBox("The Item Entered is not in database, would you like to add it?", vbYesNo) = vbYes Then
CurrentDb.Execute " INSERT INTO tbltraits(trait) Select " & Chr(34) & NewData & Chr(34) & ";", dbFailOnError
Response = acDataErrAdded
End If
End Sub
So I put it in my 'not in list' event in properties on the combo box. I updated the code to match my table name 'tbltraits' and fieldname ' trait' but its not working. The combo box doesn't even trip the 'not in list' event when I type in a value that is not in the current list. ??
Am I close to making this approach work or is there a better way?
Appreciate any help!! :o
 
Try:
Code:
Private Sub Trait_NotInList(NewData As String, Response As Integer)
   If MsgBox("The Item Entered is not in database, would you like to add it?", vbYesNo) = vbYes Then
      CurrentDb.Execute "INSERT INTO tbltraits(trait) " & _
                        "Values('" & NewData & "')", dbFailOnError
      Response = acDataErrAdded
   End If
End Sub
 
Actually I figured out my mistake. I just had to change the 'Limit to List' property to 'yes' so that the 'NotInList' event would trigger. I guess it doesn't even trigger if the 'Limit to List' property is set to 'No'
But I do have a related question. Is there some easy code that I could put in a event that could delete a value in the list?? Say a buttom that I put on my form next to the combo box that when a user selects a value in the combo box then if they click the button then it would delete the value that the user selected ??

What do you think the easiest way to do this would be??
QUOTE]
Appreciate your Help!!
 

Users who are viewing this thread

Back
Top Bottom