473,395 Members | 1,969 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,395 software developers and data experts.

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

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 3980
nico5038
3,080 Expert 2GB
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
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...
5
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...
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...
4
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...
8
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...
4
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...
4
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...
4
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...
0
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,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
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
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,...

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.