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: -
Private Sub fullcustname_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 in 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
-
Me![fullcustname].Undo
-
-
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
-
-
Thanks again
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: -
Private Sub fullcustname_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 in 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
-
Me![fullcustname].Undo
-
-
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
-
-
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: - Private Sub cmdAdd_Click( )
-
-
DoCmd.RunCommand acCmdSaveRecord
-
Forms![Name Of Your Form]![Name of the Combo Box].Requery
-
DoCmd.Close "frmAddName"
-
-
End Sub
-
-
Private Sub cmdCancel_Click()
-
-
Me.Undo
-
DoCmd.Close
-
-
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! :)
Sign in to post your reply or Sign up for a free account.
Similar topics |
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,...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| | |