473,414 Members | 1,723 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

NotInList problems

I am trying to allow the user to add an item to a list if it is not
found in a combobox. When the NotInList event is triggered I run a
function "AddItem" that has a custom dialog box to add an item to the
underlying table. The function either returns "Not Added", or the new
Items ID. I know the function works fine. Whe I try the code below I
get errors saying "Close action was cancelled" (referring to my custom
popup input box), & "The text you entered isn't an item in the list".
Then when I try to exit the form that has the combobox I get errors
saying "you must save the current field before you run the query
action" & the "you can not save this record at this time, do you still
want to exit" etc.
Does anybody see anything wrong with the code below?
Private Sub Item_NotInList(NewData As String, Response As Integer)
'create variable to hold function result
Dim AddStatus As String
AddStatus = AddItem

If AddStatus = "Not Added" Then
Response = acDataErrContinue
Else:
Response = acDataErrAdded
End If

End Sub

Jan 11 '06 #1
7 6032
Bryan <br*********@yahoo.com> wrote:
: I am trying to allow the user to add an item to a list if it is not
: found in a combobox. When the NotInList event is triggered I run a
: function "AddItem" that has a custom dialog box to add an item to the
: underlying table. The function either returns "Not Added", or the new
: Items ID. I know the function works fine. Whe I try the code below I
: get errors saying "Close action was cancelled" (referring to my custom
: popup input box), & "The text you entered isn't an item in the list".

It sounds like you haven't set the combobox's LimitToList
property to False.
--thelma
Jan 11 '06 #2
Thanks for your reply. The NotInList event can't even fire unless
LimitToList is set to yes. Any other thoughts?

Jan 11 '06 #3
Bryan <br*********@yahoo.com> wrote:
: Thanks for your reply. The NotInList event can't even fire unless
: LimitToList is set to yes. Any other thoughts?

Sorry. I'm sleepy, probably too sleepy to be making much sense.
But I think that I remember trying to do such a thing and finding
that I couldn't circumvent the LimitToList restriction that way and
had to set it False and put the code that checked for valid
addition in the BeforeUpdate event
--thelma

Jan 11 '06 #4
After looking around on several forums I'm affraid that's what I'm
going to have to do. I have not found anybody who is able to use a
custom input box function to update a combobox when the NotInList event
is fired.

Jan 11 '06 #5
Bryan wrote:
I am trying to allow the user to add an item to a list if it is not
found in a combobox. When the NotInList event is triggered I run a
function "AddItem" that has a custom dialog box to add an item to the
underlying table. The function either returns "Not Added", or the new
Items ID. I know the function works fine. Whe I try the code below I
get errors saying "Close action was cancelled" (referring to my custom
popup input box), & "The text you entered isn't an item in the list".
Then when I try to exit the form that has the combobox I get errors
saying "you must save the current field before you run the query
action" & the "you can not save this record at this time, do you still
want to exit" etc.
Does anybody see anything wrong with the code below?
Private Sub Item_NotInList(NewData As String, Response As Integer)
'create variable to hold function result
Dim AddStatus As String
AddStatus = AddItem

If AddStatus = "Not Added" Then
Response = acDataErrContinue
Else:
Response = acDataErrAdded
End If

End Sub


I googled Google Groups to find replies to NotInList questions I helped with a
long time ago. Here is the first one I found:

When I had problems with the NotInList event, I found three places that
really helped me understand what I was doing wrong:

1) http://www.mvps.org/access/forms/frm0015.htm
and

http://www.rogersaccesslibrary.com/T...ontents3.asp#N

which has these two pages:

2)
http://www.rogersaccesslibrary.com/d...Name=NotInList

3)
http://www.rogersaccesslibrary.com/d...Name=NotInList

As to your code, without seeing the function "additem" code, I don't know how
the item is being added to the table.

Maybe this will help; code from a previous post. You will have to change
field/table names......

Here is an alternate way to add to a combo box without
using an additional form. Change the control/field names
to your usage.

Set the LimitToList to YES.

In the NotInList Event: (Watch for line wrap...)

Private Sub Heading1_NotInList(NewData As String, Response As Integer)

'Cut/paste from here-----------------------
Dim db As DAO.Database
Dim rst As DAO.Recordset

' Prompt user to verify they wish to add new value.
' all one line
If MsgBox("Do you want to add '" & NewData & "' as a new
title?", vbYesNo) "Add New Item?") = vbYes Then

Set db = CurrentDb
Set rst = db.OpenRecordset("tScopeOfWorkHeaderList")
' the following adds the NewData to the table
With rst
.AddNew ' new record
!Header = NewData
.Update ' save it
End With
' close the recordset and cleanup
rst.Close
Set rst = Nothing
Set db = Nothing

' Continue without displaying default error message.
' This also does an automatic requery ******
Response = acDataErrAdded
Else
' don't add & continue
Response = acDataErrContinue
' clear the combo box
Me.Heading1.Undo
End If
'To here-----------------------
End Sub


The reason you get the error messages when you try to exit the form with the
combo box on it is because you have started to add a new record - maybe a
required field is empty (null). I think if you press the <ESC> key a couple of
times, you should be able to close the form without the errrror <g> message.

(I just noticed I misspelled error after I posted this) :D
HTH
--
Steve S.
--------------------------------
"Veni, Vidi, Velcro"
(I came, I saw, I stuck around.)
Jan 11 '06 #6
The following code works for me in a database that manages vegetable
cooking. A combo box ' cboSelCookingTypeID' gets its data from a table
'ztblLookupCookingType' which has two fields.

CookingTypeID autonumber
CookingType text

The code is as follows:-

Private Sub cboSelCookingTypeID_NotInList(NewData As String, Response
As Integer)
Dim strMsg As String
Dim rst As Recordset

strMsg = "'" & NewData & "' is not in the list of cooking types."
strMsg = strMsg & vbLf & vbLf
strMsg = strMsg & "Would you like to add it?"

If vbNo = MsgBox(strMsg, vbYesNo + vbQuestion, "New Cooking Type")
Then
Response = acDataErrDisplay
Else
Set rst = CurrentDb.OpenRecordset("ztblLookupCookingType")
rst.AddNew
rst!CookingType = NewData
rst.Update
Response = acDataErrAdded
rst.Close
End If
End Sub

When the code runs on the 'Not in list' event it pops up a message box
that gives the user the option to add the new cooking type showing what
that is (this is useful because it deals with typos). If the user wants
to add the type it is added to the table.

Hope you can adapt this to fit your problem

Geoff G

Jan 11 '06 #7

It's what's happening in the AddItem function and any anciliary code we need
to see.

--

Terry Kreft
"Bryan" <br*********@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I am trying to allow the user to add an item to a list if it is not
found in a combobox. When the NotInList event is triggered I run a
function "AddItem" that has a custom dialog box to add an item to the
underlying table. The function either returns "Not Added", or the new
Items ID. I know the function works fine. Whe I try the code below I
get errors saying "Close action was cancelled" (referring to my custom
popup input box), & "The text you entered isn't an item in the list".
Then when I try to exit the form that has the combobox I get errors
saying "you must save the current field before you run the query
action" & the "you can not save this record at this time, do you still
want to exit" etc.
Does anybody see anything wrong with the code below?
Private Sub Item_NotInList(NewData As String, Response As Integer)
'create variable to hold function result
Dim AddStatus As String
AddStatus = AddItem

If AddStatus = "Not Added" Then
Response = acDataErrContinue
Else:
Response = acDataErrAdded
End If

End Sub

Jan 11 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Pieter Linden | last post by:
Just got done reading some of ADH2000 about comboboxes and the NotInList event... Doesn't look like it's possible to tweak the behavior of this so that I can have a non-text bound column, can I?...
5
by: David Deacon | last post by:
Hi i have the following code in a CustomerID field if the user enters a notinlist customer then they should dbl click to open the customer form However this error occurs "You tried to assign a...
1
by: Steve Leferve | last post by:
Can someone tell what what objects I have to work with on the 'NotInList' event? Basically I want to have a pop-up prompt the user if they want to add the data they typed into the database. ...
2
by: whilstiwait | last post by:
I have a form containing a number of unbound combo boxes in three columns. Each column has boxes named "aaaa0", "aaaa1", etc. Using syntax like: With Forms(Me.Form.Name).Controls("txtTechnology"...
4
by: CAD Fiend | last post by:
Hello, I have a combo box (cmbFirstName) on a form that is hitting a query (qryFirstName) and then putting that selected (or typed by user) value to the table field (name FirstName) on the table...
11
by: my-wings | last post by:
I think I've painted myself into a corner, and I'm hoping someone can help me out. I have a table of books (tblBooks), which includes a field (strPubName) for Publisher Name and another field...
3
by: Bryan | last post by:
I have a listbox that the user is able to add items to through and SQL statement that is run on the NotInList event. At the end of the event, I set Response = acDataErrAdded, telling access that...
1
imrosie
by: imrosie | last post by:
Hello (from Rosie the newbie), I recently got help with a wonderful event to perform this from 'thescripts'...it recognizes that a name is not in the list an allows for (after parsing first and...
6
by: Volker Neurath | last post by:
Hi all, I have a Problem with combobox-property "NotInList" and an unbound Form. The situation: On my main form i have three comboboxes for data-exchange (here: Names of distributor,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.