473,765 Members | 2,065 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using the Combo Box's Not In List event with multiple fields

1 New Member
Hello This is the first time I've used a discusion forum and up until now I have managed to use and or modify VB code from the various sites on the web, until now!

This is a simple problem and I am trying to update a contact record with FirstName and LastName contained on a table TblContacts via a Combo Box using the Limit to List function to add new contacts and perform a search to check if the contact is new or already exists on the database.

I have modified some code published at http://www.databasedev .co.uk/multi-field-not-in-list.html which illustrates the example using the Key field set as a Long Integer rather than Autonumber. I have modified the code as shown below, but the fields do not up date. I am sure it is a typo somewhere but as being new to VB, finding this very difficult to debug. Can anyone help or this there an easier way of doing this.

Table: TblContacts
ContactID - Autonumber
FirstName - Textfield
LastName - Textfield

Form: FmCVLoader
Combo Box - Combo239
SELECT QryContactName. ContactID, QryContactName. Name FROM QryContactName ORDER BY [Name];

Query: ContactName
ContactID
Name: [FirstName] & " " & [LastName]

Expand|Select|Wrap|Line Numbers
  1.  Private Sub Combo239_NotInList(NewData As String, Response As Integer)
  2.  
  3. ' This procedure allows us to create a new value, using the NotInList event
  4. ' It passes multiple field values to the table.
  5.  
  6.     Dim strSQL
  7.     Dim NewFirstName As String
  8.     Dim NewLastName As String
  9.     Dim SpacePosition As Integer
  10.  
  11.     ' Find the space in the Actor FirstName/Last Name
  12.     ' to allow us to split the entry into two fields.
  13.     SpacePosition = InStr(NewData, " ")
  14.     If SpacePosition = 0 Then
  15.         MsgBox "Your entry has no space separating First Name and Last Name." _
  16.                & vbNewLine & vbNewLine & _
  17.                "Please enter a First and Last Name or choose an entry from " _
  18.                & "the list.", _
  19.                vbInformation, "Invalid Data !"
  20.         Response = acDataErrContinue
  21.         Exit Sub
  22.     End If
  23.  
  24.     ' Trim the data into first and last name using the space position.
  25.     NewFirstName = Trim(Left(NewData, SpacePosition - 1))
  26.     NewLastName = Trim(Mid(NewData, SpacePosition + 1))
  27.  
  28.     ' Check to see that the Actor First Name is not a
  29.     ' zero-length string. Ensure value is entered before creating
  30.     ' new Actor entry.  Place cursor at start of combo box using SelStart=0
  31.     If NewFirstName = "" Then
  32.         MsgBox "You have not entered details for the first name" _
  33.                & vbNewLine & vbNewLine & _
  34.                "Please fix entry.", vbInformation, "Invalid Data !"
  35.             Response = acDataErrContinue
  36.     End If
  37.  
  38.     ' Check to see that the Actor Last Name is not a
  39.     ' zero-length string. Ensure value is entered before creating
  40.     ' new Actor entry
  41.     If NewLastName = "" Then
  42.         MsgBox "You have not entered details for the last name" _
  43.                & vbNewLine & vbNewLine & _
  44.                "Please fix entry.", vbInformation, "Invalid Data !"
  45.         Response = acDataErrContinue
  46.         Exit Sub
  47.     End If
  48.  
  49.     ' If new entry includes First and Last Names create new Actor record
  50.     ' if the new entry does not exist.
  51.     MsgBox "A record for this person does not exist....." _
  52.            & vbNewLine & vbNewLine & _
  53.            "Now creating new Record.", vbInformation, _
  54.            "Unknown Actor Details....."
  55.     strSQL = "Insert Into TblContact ([FirstName], " & _
  56.     "[LastName]) " & _
  57.              "values ('" & NewFirstName & _
  58.              "','" & NewLastName & "');"
  59.     'MsgBox strsql
  60.     CurrentDb.Execute strSQL, dbFailOnError
  61.     Response = acDataErrAdded
  62.  
  63. End Sub
  64.  

Can anyone help Please!!!
Oct 9 '07 #1
1 3999
nico5038
3,080 Recognized Expert Specialist
The code looks OK, but has some flaws.
1) What when two John Doe's have to be entered into the system ?
2) What to do with a name like "John III Delaware", etc.
3) How is the Unique ID of the new record created ?

I guess at the moment number 3 is causing you the trouble.
When inserting a new record into a table without autonumber, you'll need to supplu the ID yourself. For this you can use a formula like: DMax("keyfield" ,"tblPerson" ) + 1

Getting the idea ?

Nic;o)
Oct 9 '07 #2

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

Similar topics

4
4762
by: Skully Matjas | last post by:
I am using the following code (created by the wizard) to allow to bring my form to a particular entery. But when I edit the entery (ex: put new information into a blank cell), it puts that record onto the bottom of the list (even though it keeps its record number). Also, There are certin names that i click on the list, and it will not bring it up, rather it brings to the first record (no matter how many times i try going to that...
5
298
by: William Bradley | last post by:
I have a need to construct a combo box that will fill in two fields, on a form,from a single table. The table: "IndexNo", "Product","Supplier","Address" etc. What I would like to do is be able to search on the "Product" field and when the correct product is found, it fills in the appropriate cell on the form and at the same time, brings up the "IndexNo" in another box. Is this
11
2805
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 (strPubCity) for Publisher City. These two fields have a many-to-one relationship with tables, (tlkpPubName and tlkpPubCity) respectively. The lookup tables only have one field (strPubName and strPubCity), which is their primary key. I also have...
4
6119
by: LD | last post by:
Is there a way in Access to store more than one value in a field that has been selected from a combo box? For example, if a combo box had three values that you can select, "One", "Two", and "Three". How do you drop down the list and select a first value ("One") then do the same and select a second value ("Two") so that the value in the field is now "One, Two". I have situations where I need to do this with fields that If there is a...
8
2203
by: AA Arens | last post by:
Hi I do have a products table and products-parts table in my Access 2003 database and log all services into a form. I do have at least the following two combo boxes on my form: - Choose Product where as the Row Source (See properties): SELECT tblProducts.ProductName, tblProducts.ProductName FROM tblProducts ORDER BY ProductName;
4
3032
by: Swinky | last post by:
I am trying to make a combo box dependent on a text box. I cannot get the combo box to pull the related data from the text box. I have been all over this user group & have tried several versions of code to no avail. I would like to display all contact names (in the combo box) related to the customer number in the text box. Here's what I have:
4
5825
by: injanib via AccessMonster.com | last post by:
I have a combo box called "Recipient" who's row source is a table called "Main" with three columns. The three columns are "Name", "Floor", "Location". Following the combo box are two fields called "Floor" and "Location". The after update event of the combo box runs the following lines to update the next two fields. = Recipient.Column(2) = Recipient.Column(3) The combo box is not limited to the values in its rowsource table. What I
4
2189
by: deanndra | last post by:
First, I want to say thank you to Scott and the others who replied to my first post here. I had to put that database on hold for the moment when I was tasked with a new one. I am building another database from scratch. This one is for job announcements. I've built only 2 tables (I know this is a no-no, but it was demanded by those wanting this database so I've complied). The field name properties and data types in both tables are virtually...
0
1958
by: Dawnyy | last post by:
I have a form which is bound to a dataset. I am filling the forms dataset on Form_Load event. On my form I have combo boxes which I am setting by running a stored procedure to return a datatable, which I then assign to the datasource. Some of my combo box datasources depend on values in other fields to limit the options. For example, I have a sales rep list that is limited by the customer selected in the customers combo box. And...
0
9568
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9404
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10168
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10008
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
9837
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
6651
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
5279
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
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3929
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.