I’ve been using an unbound combo box’s NotInList event to add new records via a second data entry form. I’d like to skip using the second form but I still need to check to see if the name is already in the database. What’s a good way to do that?
E
![]() |
There are isolated problems with current patches, but they are well-known and documented on this site. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » NotInList or something else? (A2k3)
I have to echo Hans’s question: if the item is in the list, it must be in the database, assuming the list is populated from the database. Perhaps if you clarify the problem we can answer your question. If you are using an unbound combobox to navigate to a particular record, then you can use the NotInList event to undo the combobox entry and move the form to a new record. Is that what you’re trying to accomplish?
(Edited by HansV to make URL clickable – see Help 19)
Charlotte,
Thought I was going to need help with it then ran across the following — http://www.pacificdb.com.au/MVP/Code/NIL.htm%5B/url%5D — and I was demystified. Here’s the code I’m using:
Private Sub cboFind_NotInList(NewData As String, Response As Integer)
MsgBox “Record doesn’t exist. Creating new record.”
Me.cboFind.Undo
DoCmd.GoToRecord , , acNewRec
Response = acDataErrContinue
End Sub
Thanks so much for pointing me in the right direction. I knew there has to be a way to add a new record to the existing form but I had been spinning my wheels. My stumbling block was that last line of code. It didn’t make sense to me that it came after the DoCmd, in much the same way it didn’t make sense to me that you defined your OrderBy and only then have OrderByOn. I’m learning, tho some days it feels more like knocking my head against the wall. You can teach an old dog new tricks…but sometimes we’re just incredible sllloooowwwww.
E
I think the most confusing thing about NotInList code is that you MUST supply a response, regardless of whatever else you do. Since your combobox is unbound, the move to a new record doesn’t affect it, but trying to exit the routine means that whatever response you have provided will then be processed. Once you get that firmly in mind, it starts to make sense. You could have populated the response argument earlier in the code, but there wasn’t any need to do so.
I think the most confusing thing about NotInList code is that you MUST supply a response, regardless of whatever else you do. Since your combobox is unbound, the move to a new record doesn’t affect it, but trying to exit the routine means that whatever response you have provided will then be processed. Once you get that firmly in mind, it starts to make sense. You could have populated the response argument earlier in the code, but there wasn’t any need to do so.
(Edited by HansV to make URL clickable – see Help 19)
Charlotte,
Thought I was going to need help with it then ran across the following — http://www.pacificdb.com.au/MVP/Code/NIL.htm%5B/url%5D — and I was demystified. Here’s the code I’m using:
Private Sub cboFind_NotInList(NewData As String, Response As Integer)
MsgBox “Record doesn’t exist. Creating new record.”
Me.cboFind.Undo
DoCmd.GoToRecord , , acNewRec
Response = acDataErrContinue
End Sub
Thanks so much for pointing me in the right direction. I knew there has to be a way to add a new record to the existing form but I had been spinning my wheels. My stumbling block was that last line of code. It didn’t make sense to me that it came after the DoCmd, in much the same way it didn’t make sense to me that you defined your OrderBy and only then have OrderByOn. I’m learning, tho some days it feels more like knocking my head against the wall. You can teach an old dog new tricks…but sometimes we’re just incredible sllloooowwwww.
E
I have to echo Hans’s question: if the item is in the list, it must be in the database, assuming the list is populated from the database. Perhaps if you clarify the problem we can answer your question. If you are using an unbound combobox to navigate to a particular record, then you can use the NotInList event to undo the combobox entry and move the form to a new record. Is that what you’re trying to accomplish?
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.
Notifications