473,516 Members | 3,064 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

NOTinList add names only on form, other info stored with blank name

imrosie
222 New Member
Hello (from Rosie the newbie),

I recently got help with a wonderful event to perform this from 'thescripts'...it recognizes that a name is not in the list an allows for (after parsing first and last name) for the addition of the new FullName into the Customer table. I've been working on some other forms in this application and hadn't noticed until now a little problem.

The event occurs in a 'search customer' form. You first search an already existing customer name, or add new one. What's happening is after the 'NotInList' event occurs and you've added the new name to the list, it's stored in the table, no problem. What happens next is, you begin adding other info to this 'new customer', i.e., address, phone, city, state, etc (you get the picture). BUT what's really occuring is a new record in the database ends up with all these field filled in, without a Customer Name. So in effect there are 2 records stored; one with only the new name you added (during the 'NotinLIst event) and the second record with all the fields filled in but without a name, when you close (or save) the form.

So my 'NotInList' is disconnected from the rest of the forms fields. How can I
connect them together? When I close the form, that's when the other fields are stored.
Help please, thanks, here is the code for event:

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

I recently got help with a wonderful event to perform this from 'thescripts'...it recognizes that a name is not in the list an allows for (after parsing first and last name) for the addition of the new FullName into the Customer table. I've been working on some other forms in this application and hadn't noticed until now a little problem.

The event occurs in a 'search customer' form. You first search an already existing customer name, or add new one. What's happening is after the 'NotInList' event occurs and you've added the new name to the list, it's stored in the table, no problem. What happens next is, you begin adding other info to this 'new customer', i.e., address, phone, city, state, etc (you get the picture). BUT what's really occuring is a new record in the database ends up with all these field filled in, without a Customer Name. So in effect there are 2 records stored; one with only the new name you added (during the 'NotinLIst event) and the second record with all the fields filled in but without a name, when you close (or save) the form.

So my 'NotInList' is disconnected from the rest of the forms fields. How can I
connect them together? When I close the form, that's when the other fields are stored.
Help please, thanks, here is the code for event:

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

The code you got is quite confusing. I wonder how you understood it.

Here is what I suggest you to do.
I want you to make a form bound to the table where you have the customer name field on.

Let's say you name it frmAddName
in the frmAddName, just add the combo box of the CustomerName field.
Let's say the name of this field is [CustName]
Then add two command buttons. one is named cmdAdd, and one is cmdCancel

Program the two command buttons as follow:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdAdd_Click( )
  2.  
  3.     DoCmd.RunCommand acCmdSaveRecord
  4.     Forms![Name Of Your Form]![Name of the Combo Box].Requery
  5.     DoCmd.Close "frmAddName"    
  6.  
  7. End Sub
  8.  
  9. Private Sub cmdCancel_Click()
  10.  
  11.     Me.Undo
  12.     DoCmd.Close
  13.  
  14. End Sub

That should do it for this form. This is where user would add the new name.




Let's go to your form. On the NotInList event of you combo box, program
it like this:

Private Sub NameOfYourComboBox_NotInList(NewData As String, Response As Integer)

MsgBox "The Name you entered is not yet in the list" & _
vbCrLf & "Double Click to Add a new name", _
vbInformation, "Name Not Found"
Response = DataErrCont

End Sub

On the DblClick Event of your combo box, program it like this.

Me.[NameOfYourComboBox] = ""
DoCmd.OpenForm "frmAddName"



Try it. This is the scenario, when the user input a name not in the list,
he would receive the message:
' The name you entered is not in the list.
Double Click to add a new name '

Then the user clicks OK on the message box.

The user would now then double click the combobox.
This would open the frmAddName I asked you to make.

The user would type that new name in the text box and Clicks ADD.
Since the form is bound to the table where the name is saved on that table
and the combo box on the Your Form is refreshed.

The user may now select that newly added name in the combo box.

Enjoy! :)
Jun 26 '07 #2

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

Similar topics

7
3202
by: JDS | last post by:
Hi, all. I'd like to do the following, preferably *without* resorting to JavaScript: I have a long, dynamically-generated form questionnaire. Not all of the form fields are dynamically generated, though. I'd like to capture the NAME of every HTML form field element on the server, even if that element is submitted blank. The trouble is,...
3
2788
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? Say I have a Customers--Invoices relationship, and I want to be able to pick the Customer's name from a combobox. (keeps people from entering the...
2
2209
by: whilstiwait | last post by:
I have a form containing a number of unbound combo boxes in three columns. Each column has boxes named "aaaa0", "aaaa1", etc. Using syntax like: With Forms(Me.Form.Name).Controls("txtTechnology" & i) .AfterUpdate = "=txtTechnology_Change(" & i & ")" .OnEnter = "=txtTechnology_OnEnter(" & i & ")" End With I can set events to a common...
4
1786
by: CAD Fiend | last post by:
Hello, I have a combo box (cmbFirstName) on a form that is hitting a query (qryFirstName) and then putting that selected (or typed by user) value to the table field (name FirstName) on the table (tblUserInfo). The query hits a look up table called (lulFirstNames). If the user DOESN'T find the name they want in the combo box, they will...
11
2778
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...
7
6041
by: Bryan | last post by:
I am trying to allow the user to add an item to a list if it is not found in a combobox. When the NotInList event is triggered I run a function "AddItem" that has a custom dialog box to add an item to the underlying table. The function either returns "Not Added", or the new Items ID. I know the function works fine. Whe I try the code below...
1
3683
by: JHite | last post by:
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...
4
4953
by: EManning | last post by:
I have a combobox whose rowsource is a union query. This query displays a person's name in "lastname, firstname" format and in "firstname lastname" format. The query results look like this: Mouse, Mickey Mickey Mouse When a person is added, the querys' underlying recordset is updated in the NotInList event. I can't figure out how to...
6
2664
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...
0
7581
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...
1
7142
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7548
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...
0
5714
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...
1
5110
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...
0
4773
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...
0
1624
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
1
825
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
488
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...

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.