473,795 Members | 3,048 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Add new record via form where data entered is NotInList

18 New Member
I am using Access 2003. My Form has 4 fields:
MailingListID, auto generated – primary key
LastName
FirstName
NickName

I used the Combo box wizard to set up look-up box on the form. I answered the wizards question by saying “find a record in the form”, I choose the first 3 fields for the combo box and made field 1 width = 0. The wizard then created the unbound control box and generated the code shown below

Private Sub Combo14_AfterUp date()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Cl one
rs.FindFirst "[MailingListID] = " & Str(Nz(Me![Combo14], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

This seems to work fine. I can pull down on the list and click on the name I want and info for that record shows up in form or if I enter a last name not on the pull down list, I get the usual error message for not in list.

I thought it would be simple to modify Combo14 to simply add a new record if it didn’t find the LastName I typed in. So I modified Combo14 as you see below. But I still get the not in list error message when I try it - instead of the form for the new record – which should have the next autonumber in the MailingListID field and “Doe” in the LastName field. [Actually in real life I would capture the LastName the user typed and put that in instead of Doe but I’m just trying to get this to work.]

Private Sub Combo14_AfterUp date()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Cl one
rs.FindFirst "[MailingListID] = " & Str(Nz(Me![Combo14], 0))
If Not rs.EOF Then
Me.Bookmark = rs.Bookmark
Else
rs.AddNew
rs!LastName = "Doe"
rs.Update
Me.Bookmark = rs.Bookmark
End If

End Sub

What should the procedure look like to do what I want?

PostScript: I also tried leaving Combo_14 as the wizard created and putting a macro GoToRecord (new) in the NotInList event field. But this caused Access to abruptly shut down.

Thanks for any help. J Hite
Nov 8 '06 #1
1 3707
MMcCarthy
14,534 Recognized Expert Moderator MVP
You cannot add value by typing into combo box. Type last name in an unbound text box. Then check this out ...

Expand|Select|Wrap|Line Numbers
  1.  
  2. ' change to after update event on new textbox 
  3. Private Sub textboxname_AfterUpdate()
  4. ' Find the record that matches the control.
  5. Dim rs As Recordset ' declare as recordset rather than object
  6.  
  7. ' this assumes that form is bound to relevant table or query and fields are bound on the form 
  8. Set rs = Me.RecordsetClone ' no dot between recordset and clone
  9. rs.FindFirst "[LastName]='" & Me.[textboxname] & "'" ' lookup lastname in records on form
  10.  
  11. If rs.NoMatch Then ' if name not found then
  12. rs.AddNew ' add new record
  13. rs!LastName = Me.[textboxname] ' set LastName to value typed in
  14. rs.Update
  15. End If
  16.  
  17. ' always reset recordset
  18. rs.Close
  19. Set rs = Nothing
  20.  
  21. Me.Combo14.Requery ' requery the combo box to show new record
  22.  
  23. End Sub
  24.  
  25.  
Nov 9 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
3944
by: Steve | last post by:
I have a form, primary subform and secondary subform. A tab control takes up all the area of the primary subform. There are about 15 tabs on the tabcontrol. Each tab contains fields from the same table. Related fields appear on each tab. There is one field in the table that needs to be displayed at all times so I created the secondary subform (subform to main form) to display just that one field. Data entry is main form - secondary subform...
6
3077
by: 6thirty | last post by:
Hi, I've created a stocktaking database using Access XP. This is indexed by two fields - part number and shelf location. I am currently inputting all the data via a form. When I have entered a record such as: part number 202354-001 location C1-01
3
6961
by: Tom | last post by:
Say a form has a subform, a button that pops up a message box and a cancel button. Q1. If data is entered in one or more fields on the main form and the user then clicks the button that opens the message box, is the record saved? Q2. What is the best way to determine if the main form record has been saved so code could be written to undo the main form if the record has not been saved and delete the record if it has been saved? Q3. ...
5
3346
by: Ross A. Finlayson | last post by:
Hi, I'm scratching together an Access database. The development box is Office 95, the deployment box Office 2003. So anyways I am griping about forms and global variables. Say for example I'm adding a customer. The Customer fields are mostly foreign keys that refer to primary keys in other tables, left join instead of junction tables at this point. So, when I want to add a customer record, I also need to add records to the other...
6
2609
by: kaosyeti | last post by:
hey.... i have a duplicate record issue i could use some help with. on a form that has 2 unbound controls, txtboxyear and cboxmonth, together will automatically fill in an invisible txtboxdate that is bound to a table and has no duplicates allowed. the problem is that there are 30 or so other controls here to be filled in and if the user selects a year and month that already has a record created, she/he won't know it until access tries to...
10
1917
by: robingSA | last post by:
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...
5
1872
AccessIdiot
by: AccessIdiot | last post by:
This is kind of an odd request. I have a form with a combo box. If an item isn't in the combo box you can add it by launching a new form (using NotInList). I would like for the main form to go right to a new record when the form is launched. I have code on the Load event that does this quite nicely. However, when the form to add to the combo box is launched and then closed it automatically causes the main form to advance to the next new...
18
2661
by: Drayno241 | last post by:
I'm working in access 2002. I have three tables : 1- District Data (Student ID, name, grade, etc) 2- Rosters (RRec ID,Campus, Teacher ID) 3- Students on Roster(SRec ID, RRec ID, Student ID) There's a 1 to many relationship between Rosters and Students on Roster. I created a form and subform to populate the Rosters and Students on Roster. The Students on Roster subform simply accepts the Student ID's (datasheet format) and if the...
6
2691
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, reseller and final customers, the whole database is made for storing information about quotatations - no, not for quoting itself) ut the boxes actually may not contain all our distributors and reseller's
0
10215
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10001
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9043
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7541
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6783
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.