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

Help...notinlist creating 2 of same customer name in table

imrosie
222 100+
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., address, city, phone etc.)...I end up with two separate entries of the same customer (different customer id's (assigned through an autonumber)

I found this out after looking in the Customer table to see that 1st the name goes into the Customer table, but without any of the data. The second customer has all the data I typed in, but without a name...

Here's the code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub custname_NotInList(NewData As String, Response As Integer)
  2. Private Sub custname_NotInList(NewData As String, Response As Integer)
  3. Dim intAnswer As Integer
  4. Dim strSQL As String
  5. Dim strFirstName As String, strLastName As String, strFullName As String    'for capturing the parsed components of FullName
  6. 'the FullName entered is not the table list; prompt user to ok adding it to list
  7.  intAnswer = MsgBox("" & Chr(34) & NewData & _
  8. Chr(34) & " isnīt on the list." & vbCrLf & _
  9.  "Would you like to add it?" _
  10.  , vbQuestion + vbYesNo, "Express")
  11.  
  12. ' Background process for Parsing FullName entry into first and last name
  13. strFullName = Trim(CStr(NewData)) ' Change Variant to String
  14. If InStr(1, strFullName, ",") = 0 Then     'FullName entered----> First Last
  15.      strFirstName = Left(strFullName, InStr(strFullName, " ") - 1)
  16.      strLastName = Right(strFullName, Len(strFullName) - InStrRev(strFullName, " "))
  17. ElseIf InStr(1, strFullName, ",") > 0 Then  'FullName entered----> Last, First
  18.      strLastName = Left(strFullName, InStr(strFullName, ",") - 1)
  19.      strFirstName = Right(strFullName, Len(strFullName) - InStrRev(strFullName, ",") - 1)
  20. Else
  21.      MsgBox "You've entered the name without a comma between the first and last name."
  22.      Exit Sub
  23.      End If
  24.   'insert parsed components captured in strFullName, strFirstName, and strLastName to the table
  25. strSQL = "INSERT INTO Customers(FullName, FirstName, LastName)" & _
  26.   "VALUES ('" & strFullName & "', '" & strFirstName & "', '" & strLastName & "');"
  27.    DoCmd.SetWarnings False
  28.    DoCmd.RunSQL strSQL
  29.    DoCmd.SetWarnings True
  30.     If intAnswer = vbYes Then
  31.   MsgBox "The name has been added to the list." _
  32.    , vbInformation, "Express"
  33.  'acDataAdded causes the combobox to get requeried, the new item is selected, and the focus moves
  34.    Response = acDataErrAdded
  35. Else
  36.   MsgBox "Please select a name on the list." _
  37.  , vbInformation, "Express"
  38.  Response = acDataErrContinue
  39.  End If
  40.  
  41. End Sub
  42.  

I wrestled with this for a long time and just can't figure out how to correct it...help.
Rosie
Jul 25 '07 #1
4 1750
nico5038
3,080 Expert 2GB
Storing a Fullname and the First and LastName is known as the creation of redundant data. You'll experience trouble when afterwards someone edits the Lastname and not the FullName.....
In a normalized table we only record FirstName and LastName and when we need the FullName we use a concatenation of the two fields. That way we can control the name and have "John Doe" or "Doe, John" as we like (or need).

This will however make it impossible to use one combobox for the selection.
Personally I use a mainform with a datasheet subform, allowing the user to filter on multiple fields (Like LastName, FirstName, Town, DayOfBirth, etc) to find out or his "new" client is already known. Then a [Add] button can be used to add a new client. Optionally you could show a message when someone with the entered name on the Add-form already exists, but keep in mind that typo's are easily made.

For the filtering I give my users the following instruction:
http://www.geocities.com/nico5038/xR...nstruction.zip
and as a sample of a datasheet subform and the [Add] button check:
http://www.geocities.com/nico5038/xS...tAction-97.zip

Nic;o)
Jul 27 '07 #2
imrosie
222 100+
Storing a Fullname and the First and LastName is known as the creation of redundant data. You'll experience trouble when afterwards someone edits the Lastname and not the FullName.....
In a normalized table we only record FirstName and LastName and when we need the FullName we use a concatenation of the two fields. That way we can control the name and have "John Doe" or "Doe, John" as we like (or need).

This will however make it impossible to use one combobox for the selection.
Personally I use a mainform with a datasheet subform, allowing the user to filter on multiple fields (Like LastName, FirstName, Town, DayOfBirth, etc) to find out or his "new" client is already known. Then a [Add] button can be used to add a new client. Optionally you could show a message when someone with the entered name on the Add-form already exists, but keep in mind that typo's are easily made.

For the filtering I give my users the following instruction:
http://www.geocities.com/nico5038/xR...nstruction.zip
and as a sample of a datasheet subform and the [Add] button check:
http://www.geocities.com/nico5038/xS...tAction-97.zip

Nic;o)
Nic;o

Thanks for your direction, I'm going to get busy with this one now to see if I can ever get out of the situation I'm in. I'll post back the result for the sake of others. thanks

Rosie
Jul 27 '07 #3
nico5038
3,080 Expert 2GB
Keep me posted and don't hesitate to ask clarification.
The approach I proposed is called the "Object/Action" principle and resembles the way most Windows applications and also Access does work. Check out the database window for tables, forms and reports and see the same "action" buttons, although positioned in another place :-)

Nic;o)
Jul 27 '07 #4
imrosie
222 100+
Keep me posted and don't hesitate to ask clarification.
The approach I proposed is called the "Object/Action" principle and resembles the way most Windows applications and also Access does work. Check out the database window for tables, forms and reports and see the same "action" buttons, although positioned in another place :-)

Nic;o)
Hi Nic;o..

I'm a newbie andthat was a bit over my head.....I just need a simple procedure to add a new name to the list when it's not in the list,,,,,,,,,,,without it creating two, not one, entry in the Customer table. thanks if you have something for a newer person to all this Vb.
Rosie
Jul 28 '07 #5

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

Similar topics

0
by: MSM | last post by:
Hello, This may be posted twice if so i apologize. I am creating a form using php where the information entered into the form will go into a database. When creating the tables in SQL where do I...
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: David Mitchell | last post by:
I have a combobox which has the following SQL Statement as its Data Source SELECT DISTINCTROW tblCustomer.CustomerID, Trim(! & " " & ! & " " & !) AS Customer FROM tblCustomer ORDER BY Trim(!...
9
by: Tony Williams | last post by:
I have two tables 1.tblmonth which holds two fields txtmonth and txtqtrlabel and 2. tblmain which holds a number of fields but in particular a field called txtqtrlabel2. The two tables are linked...
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...
2
by: mcmahonb | last post by:
Hello people, I'm fairly new to access and DB programming in general. I am familiar with the "basics" of MS Access, forms, tables, queries, macros, and such, but still don't have everything down...
2
imrosie
by: imrosie | last post by:
Hello, I have a search form that uses a row query to locate a customer by customerID and first & last names, so it's an unbound control. I also have two events associated with this control,...
1
imrosie
by: imrosie | last post by:
Please help with this one,,,,,I've been trying everything in my arsenal to fix this one. I'm stumped.... I"ve got a unbound combo box (customername) that has two events (on click); AfterUpdate and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.