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] - Private Sub Combo239_NotInList(NewData As String, Response As Integer)
-
-
' This procedure allows us to create a new value, using the NotInList event
-
' It passes multiple field values to the table.
-
-
Dim strSQL
-
Dim NewFirstName As String
-
Dim NewLastName As String
-
Dim SpacePosition As Integer
-
-
' Find the space in the Actor FirstName/Last Name
-
' to allow us to split the entry into two fields.
-
SpacePosition = InStr(NewData, " ")
-
If SpacePosition = 0 Then
-
MsgBox "Your entry has no space separating First Name and Last Name." _
-
& vbNewLine & vbNewLine & _
-
"Please enter a First and Last Name or choose an entry from " _
-
& "the list.", _
-
vbInformation, "Invalid Data !"
-
Response = acDataErrContinue
-
Exit Sub
-
End If
-
-
' Trim the data into first and last name using the space position.
-
NewFirstName = Trim(Left(NewData, SpacePosition - 1))
-
NewLastName = Trim(Mid(NewData, SpacePosition + 1))
-
-
' Check to see that the Actor First Name is not a
-
' zero-length string. Ensure value is entered before creating
-
' new Actor entry. Place cursor at start of combo box using SelStart=0
-
If NewFirstName = "" Then
-
MsgBox "You have not entered details for the first name" _
-
& vbNewLine & vbNewLine & _
-
"Please fix entry.", vbInformation, "Invalid Data !"
-
Response = acDataErrContinue
-
End If
-
-
' Check to see that the Actor Last Name is not a
-
' zero-length string. Ensure value is entered before creating
-
' new Actor entry
-
If NewLastName = "" Then
-
MsgBox "You have not entered details for the last name" _
-
& vbNewLine & vbNewLine & _
-
"Please fix entry.", vbInformation, "Invalid Data !"
-
Response = acDataErrContinue
-
Exit Sub
-
End If
-
-
' If new entry includes First and Last Names create new Actor record
-
' if the new entry does not exist.
-
MsgBox "A record for this person does not exist....." _
-
& vbNewLine & vbNewLine & _
-
"Now creating new Record.", vbInformation, _
-
"Unknown Actor Details....."
-
strSQL = "Insert Into TblContact ([FirstName], " & _
-
"[LastName]) " & _
-
"values ('" & NewFirstName & _
-
"','" & NewLastName & "');"
-
'MsgBox strsql
-
CurrentDb.Execute strSQL, dbFailOnError
-
Response = acDataErrAdded
-
-
End Sub
-
Can anyone help Please!!!
1 3980
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)
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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: 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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
|
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...
|
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,...
| |