NotInList

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.
 
X

XPS350

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
 

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