473,405 Members | 2,338 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,405 software developers and data experts.

NotInList adding new entry as a new record each time

Hi...I have a number of Combo Boxes on a form. If one types a name
which is not in the table, I want it to add the typed, new item. I am
using the following code to do this and it works well, except for one
thing - each new item is added as a new record. I want the new name to
be added after the last entry in the relevant field...is this possible
- preferably by tweaking the code I am using already?

Private Sub Supermarket_NotInList(NewData As String, Response As
Integer)
Dim Db As DAO.Database
Dim Rs As DAO.Recordset
Dim Msg As String
Msg = "'" & NewData & "' is not in the list." & vbCr & vbCr
Msg = Msg & "Do you want to add it?"
If MsgBox(Msg, vbQuestion + vbYesNo) = vbNo Then
Response = acDataErrContinue
MsgBox "Try again."
Else
Set Db = CurrentDb
Set Rs = Db.OpenRecordset("Businesses", dbOpenDynaset)
Rs.AddNew
Rs![Supermarket] = NewData
Rs.Update
Response = acDataErrAdded
End If
End Sub

Thanks...Rob

May 17 '06 #1
10 1891
If you have an autonumber in your table, sort "Businesses" on the autonumber
field ascending or descending depending on how you want to see the list. Add
the following line to your code after Response = acDataErrAdded:
Me!NameOfCombobox.Requery

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
Over 1175 users have come to me from the newsgroups requesting help
re******@pcdatasheet.com

<ro******@gmail.com> wrote in message
news:11**********************@j73g2000cwa.googlegr oups.com...
Hi...I have a number of Combo Boxes on a form. If one types a name
which is not in the table, I want it to add the typed, new item. I am
using the following code to do this and it works well, except for one
thing - each new item is added as a new record. I want the new name to
be added after the last entry in the relevant field...is this possible
- preferably by tweaking the code I am using already?

Private Sub Supermarket_NotInList(NewData As String, Response As
Integer)
Dim Db As DAO.Database
Dim Rs As DAO.Recordset
Dim Msg As String
Msg = "'" & NewData & "' is not in the list." & vbCr & vbCr
Msg = Msg & "Do you want to add it?"
If MsgBox(Msg, vbQuestion + vbYesNo) = vbNo Then
Response = acDataErrContinue
MsgBox "Try again."
Else
Set Db = CurrentDb
Set Rs = Db.OpenRecordset("Businesses", dbOpenDynaset)
Rs.AddNew
Rs![Supermarket] = NewData
Rs.Update
Response = acDataErrAdded
End If
End Sub

Thanks...Rob

May 17 '06 #2

"PC Datasheet" <No****@Spam.Com> schreef in bericht news:me****************@newsread3.news.pas.earthli nk.net...

--
--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications 'Resource ????
Over 1175 users have come to me from the newsgroups requesting help '1175 users ????
re******@pcdatasheet.com


--
To Steve:
No-one wants your advertising/job hunting here!
Over 875 !! users from the newsgroups have visited the website to read what kind of a 'resource' you are... (rapidly increasing..)

To the original poster:
Most people here have a common belief that the newsgroups are for *free exchange of information*.
But Steve is a notorious job hunter in these groups, always trying to sell his services.
And he is known here as a shameless liar with no ethics at all.

Before you intend to do business with him look at:
http://home.tiscali.nl/arracom/whoissteve.html

Arno R
May 17 '06 #3
Whats worse than his advertising is his sending emails to the person who
asks the question trying to get them to pay him to help them.

Really makes you not want to even write to the group anymore.

I've gotten my share of emails from him offering his help for a fee.



"StopThisAdvertising" <StopThisAdvertising@DataShit> wrote in message
news:44**********************@text.nova.planet.nl. ..

"PC Datasheet" <No****@Spam.Com> schreef in bericht
news:me****************@newsread3.news.pas.earthli nk.net...

--
--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications 'Resource ???? Over 1175 users have come to me from the newsgroups requesting help '1175 users ???? re******@pcdatasheet.com


--
To Steve:
No-one wants your advertising/job hunting here!
Over 875 !! users from the newsgroups have visited the website to read what
kind of a 'resource' you are... (rapidly increasing..)

To the original poster:
Most people here have a common belief that the newsgroups are for *free
exchange of information*.
But Steve is a notorious job hunter in these groups, always trying to sell
his services.
And he is known here as a shameless liar with no ethics at all.

Before you intend to do business with him look at:
http://home.tiscali.nl/arracom/whoissteve.html

Arno R
May 17 '06 #4

"Doc Holiday" <te**********@yahoo.com> schreef in bericht news:5V*****************@tornado.texas.rr.com...
Whats worse than his advertising is his sending emails to the person who
asks the question trying to get them to pay him to help them.

Really makes you not want to even write to the group anymore.



I've gotten my share of emails from him offering his help for a fee.


Hmmm,
I am beginning to think that Steve spammed 1175 people ... ???
Could you show me (email me) these unwanted emails please?

I will be glad to expand the info on this topic on the website if you don't mind.
I might even might make a new page.

Arno R
May 17 '06 #5
Sent you what i hadnt deleted.
"Arno R" <ar***********@tiscali.nl> wrote in message
news:44**********************@text.nova.planet.nl. ..

"Doc Holiday" <te**********@yahoo.com> schreef in bericht
news:5V*****************@tornado.texas.rr.com...
Whats worse than his advertising is his sending emails to the person who
asks the question trying to get them to pay him to help them.

Really makes you not want to even write to the group anymore.

I've gotten my share of emails from him offering his help for a fee.


Hmmm,
I am beginning to think that Steve spammed 1175 people ... ???
Could you show me (email me) these unwanted emails please?

I will be glad to expand the info on this topic on the website if you don't
mind.
I might even might make a new page.

Arno R
May 17 '06 #6
ro******@gmail.com wrote in
news:11**********************@j73g2000cwa.googlegr oups.com:
Hi...I have a number of Combo Boxes on a form. If one types a
name which is not in the table, I want it to add the typed,
new item. I am using the following code to do this and it
works well, except for one thing - each new item is added as a
new record. I want the new name to be added after the last
entry in the relevant field...is this possible - preferably by
tweaking the code I am using already?

Private Sub Supermarket_NotInList(NewData As String, Response
As Integer)
Dim Db As DAO.Database
Dim Rs As DAO.Recordset
Dim Msg As String
Msg = "'" & NewData & "' is not in the list." & vbCr &
vbCr Msg = Msg & "Do you want to add it?"
If MsgBox(Msg, vbQuestion + vbYesNo) = vbNo Then
Response = acDataErrContinue
MsgBox "Try again."
Else
Set Db = CurrentDb
Set Rs = Db.OpenRecordset("Businesses",
dbOpenDynaset)
Rs.AddNew
Rs![Supermarket] = NewData
Rs.Update
Response = acDataErrAdded
End If
End Sub

Thanks...Rob


The code between the Else and End If is what is the problem. I'd
need to know the recordsource of your combobox before being sure,
but I think you want to change the code to
Else
me.[supermarket] = newdata
Response = acDataErrAdded
End IF

Post the recordsource for the combobox. If it's a named query, post
that as well.

--
Bob Quintal

PA is y I've altered my email address.
May 17 '06 #7
"PC Datasheet" <No****@Spam.Com> wrote in
news:me****************@newsread3.news.pas.earthli nk.net:
If you have an autonumber in your table, sort "Businesses" on
the autonumber field ascending or descending depending on how
you want to see the list. Add the following line to your code
after Response = acDataErrAdded: Me!NameOfCombobox.Requery

Bzzzzt! Wrong Answer.
--
Bob Quintal

PA is y I've altered my email address.
May 17 '06 #8
Thanks. Had no intentions of going any further with Steve - idiot. Why
would anyone pay someone when there are more competent experts on the
newsgroups who are willing to help for nothing?

Bob - do you mean the Row Source? If so, it is:
SELECT [Businesses].[Supermarket] FROM Businesses;

If I use your code above, I get the error message that "The text you
entered isn't an item in the list. Select an item from the list....

May 18 '06 #9
"PC Datasheet" <No****@Spam.Com> wrote in message
news:me****************@newsread3.news.pas.earthli nk.net...
If you have an autonumber in your table, sort "Businesses" on the
autonumber field ascending or descending depending on how you want to see
the list. Add the following line to your code after Response =
acDataErrAdded:
Me!NameOfCombobox.Requery


Hahahahahaha ... oww, my sides, stop it ... ahhhh hahahaha! And I thought
Frasier was funny ...
May 18 '06 #10
ro******@gmail.com wrote in
news:11*********************@j73g2000cwa.googlegro ups.com:
Thanks. Had no intentions of going any further with Steve -
idiot. Why would anyone pay someone when there are more
competent experts on the newsgroups who are willing to help
for nothing?

Bob - do you mean the Row Source? If so, it is:
SELECT [Businesses].[Supermarket] FROM Businesses;

If I use your code above, I get the error message that "The
text you entered isn't an item in the list. Select an item
from the list....

OK, What is happening is this: your form and the combobox use the
same table. Until you update the table you can't get the data
you've entered to appear in the combobox. You can't update the
table unless the data has been added to the combobox.

Quick fix: Set the limit to list property to no..

The right way to fix this is to have a separate table containing
the lookup values for your combobox. Then you'd use the code you
posted to write to the lookup table, which then requeries the table
and allows it to be used..

Actually, database design theory says you should put a numeric ID
in your lookup table and the text, and store the ID in your main
table. It saves space and makes for easier changes when you need to
modify a lookup value.

--
Bob Quintal

PA is y I've altered my email address.
May 18 '06 #11

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?...
0
by: mal | last post by:
Have tried numerous ideas from the group to solve this one. It is such a simple example that it should be straightforward ! I just want to add a new item to a combo that has data from a file, by...
3
by: mal | last post by:
Sorry for repost - system added to another subject for some reason Have tried numerous ideas from the group to solve this one. It is such a simple example that it should be straightforward ! I...
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...
7
by: Bryan | last post by:
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...
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...
4
imrosie
by: imrosie | last post by:
Hello, I need help. I have a 'NotInlist' routine that appears to givbe me 2 entries of the same new customer. It first adds the name to the list, then when I fill in other customer data (i.e.,...
4
by: EManning | last post by:
I have a combobox whose rowsource is a union query. This query displays a person's name in "lastname, firstname" format and in "firstname lastname" format. The query results look like this: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
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,...

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.