NotInList

  • Thread starter Thread starter Ivor Williams
  • Start date Start date
I

Ivor Williams

I have a combo box on a form which uses as a record source a table. The
Limit To List property is set to yes. I have another form for new entries
which I want to open whenever an entry in the combo box does not match
anything in the list.
Then the user can enter the necessary information on the new entry form and
close it, making the new entry available in the combo box. Can someone
please suggest some code to make this work.
 
I have a combo box on a form which uses as a record source a table. The
Limit To List property is set to yes. I have another form for new entries
which I want to open whenever an entry in the combo box does not match
anything in the list.
Then the user can enter the necessary information on the new entry form and
close it, making the new entry available in the combo box. Can someone
please suggest some code to make this work.

You can try something like:

Private Sub YourField_NotInList(NewData As String, Response As
Integer)
If MsgBox("Vaulue not in list" & vbLf & vbLf & "Add it?", vbYesNo,
"Not in list") = vbYes Then
Response = acDataErrAdded
DoCmd.RunSQL "INSERT INTO YourTable(YourField) VALUES('" & NewData
& "')"
DoCmd.OpenForm "YourForm", , , "YourField='" & NewData & "'"
Else
Response = acDataErrContinue
Me.SoortDier.Undo
End If
End Sub

Peter
http://access.xps350.com
 
Back
Top