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: - Private Sub custname_NotInList(NewData As String, Response As Integer)
-
Private Sub custname_NotInList(NewData As String, Response As Integer)
-
Dim intAnswer As Integer
-
Dim strSQL As String
-
Dim strFirstName As String, strLastName As String, strFullName As String 'for capturing the parsed components of FullName
-
'the FullName entered is not the table list; prompt user to ok adding it to list
-
intAnswer = MsgBox("" & Chr(34) & NewData & _
-
Chr(34) & " isnīt on the list." & vbCrLf & _
-
"Would you like to add it?" _
-
, vbQuestion + vbYesNo, "Express")
-
-
' Background process for Parsing FullName entry into first and last name
-
strFullName = Trim(CStr(NewData)) ' Change Variant to String
-
If InStr(1, strFullName, ",") = 0 Then 'FullName entered----> First Last
-
strFirstName = Left(strFullName, InStr(strFullName, " ") - 1)
-
strLastName = Right(strFullName, Len(strFullName) - InStrRev(strFullName, " "))
-
ElseIf InStr(1, strFullName, ",") > 0 Then 'FullName entered----> Last, First
-
strLastName = Left(strFullName, InStr(strFullName, ",") - 1)
-
strFirstName = Right(strFullName, Len(strFullName) - InStrRev(strFullName, ",") - 1)
-
Else
-
MsgBox "You've entered the name without a comma between the first and last name."
-
Exit Sub
-
End If
-
'insert parsed components captured in strFullName, strFirstName, and strLastName to the table
-
strSQL = "INSERT INTO Customers(FullName, FirstName, LastName)" & _
-
"VALUES ('" & strFullName & "', '" & strFirstName & "', '" & strLastName & "');"
-
DoCmd.SetWarnings False
-
DoCmd.RunSQL strSQL
-
DoCmd.SetWarnings True
-
If intAnswer = vbYes Then
-
MsgBox "The name has been added to the list." _
-
, vbInformation, "Express"
-
'acDataAdded causes the combobox to get requeried, the new item is selected, and the focus moves
-
Response = acDataErrAdded
-
Else
-
MsgBox "Please select a name on the list." _
-
, vbInformation, "Express"
-
Response = acDataErrContinue
-
End If
-
-
End Sub
-
I wrestled with this for a long time and just can't figure out how to correct it...help.
Rosie
4 1750
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)
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
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)
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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?...
|
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...
|
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(!...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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,...
|
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...
| |