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

Please Help....Getting double entries using recordset (AfterUpdate)

imrosie
222 100+
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 NotInList.

The AfterUpdate uses a 'me.recordsetclone' in order to display other data in controls associated with customerid/customername from the Customer table.

The NotInlist, does just that, adds a new customer name to the
list along with a new autonumber (used as customerid).

The problem is that I'm getting two entries (different autonumbers). I can't figure out what I'm doing wrong. If I remove the 'AfterUpdate' event, then I can't bring up the customer's data, since then there's no connection to the customername/customerid.

If I remove the Not in List, then there's no way to add a new customer. I reconfigured NotInList many many times and still I get 2 entries. One entry has Customer 'name only', The second entry has name, address, city and the rest of the fields as entered.

I tried setting an index (on Customer table) with CustID and CustomerID, making them unique, but still I'm getting 2 entries whenever I use the 'NotInList'..........Help Help,,

Here are these events:
Expand|Select|Wrap|Line Numbers
  1. Private Sub customername_AfterUpdate()
  2. Dim rst As Object
  3.  
  4. Set rst = Me.RecordsetClone
  5.  
  6. rst.FindFirst "CustomerID=" & Me![customername]
  7. If Not rst.NoMatch Then
  8.  
  9.   Me.Bookmark = rst.Bookmark
  10. Else
  11.   'Not found!
  12. End If
  13. Forms![Add or Delete Customer]![customername].Requery
  14. End Sub
  15.  
Expand|Select|Wrap|Line Numbers
  1. Private Sub customername_NotInList(NewData As String, Response As Integer)
  2. Dim strSQL
  3. Dim FirstName As String
  4. Dim LastName As String
  5. Dim SpacePosition As Integer
  6. Dim lngNextID As Long
  7.  
  8.     ' Find the highest Cust ID in the Customers table and add 1
  9.     lngNextID = DMax("[CustID]", "Customers") + 1
  10.     custID = lngNextID
  11.  
  12.    SpacePosition = InStr(NewData, " ")
  13.     If SpacePosition = 0 Then
  14.         MsgBox "Your entry requires a space to separate First and Last name." & _
  15.                vbNewLine & vbNewLine & _
  16.                "Please enter a First and Last Name or choose an entry from the list.", _
  17.                vbInformation, "Invalid Data !"
  18.         Response = acDataErrContinue
  19.         Exit Sub
  20.     End If
  21.  
  22.     ' Trim the data into first and last name using the space position.
  23.     FirstName = Trim(Left(NewData, SpacePosition - 1))
  24.     LastName = Trim(Mid(NewData, SpacePosition + 1))
  25.  
  26.     If FirstName = "" Then
  27.         MsgBox "You have not entered details for the first name" & vbNewLine & vbNewLine & _
  28.                "Please fix entry.", vbInformation, "Invalid Data !"
  29.         Response = acDataErrContinue
  30.         Exit Sub
  31.     End If
  32.  
  33.     If LastName = "" Then
  34.         MsgBox "You have not entered details for the last name" & vbNewLine & vbNewLine & _
  35.                "Please fix entry.", vbInformation, "Invalid Data !"
  36.         Response = acDataErrContinue
  37.         Exit Sub
  38.     End If
  39.  
  40.     MsgBox "An account for this person does not exist....." & vbNewLine & vbNewLine & _
  41.            "Now creating new Customer Account.", vbInformation, "Unknown Customer Details....."
  42.     strSQL = "Insert Into Customers ([custID], [FirstName], [LastName]) " & _
  43.     "values ('" & custID & "','" & FirstName & "','" & LastName & "');"
  44.     'MsgBox strsql
  45.     CurrentDb.Execute strSQL, dbFailOnError
  46.     Response = acDataErrAdded
  47.  
  48. End Sub
  49.  
CustID is NOT an autonumber. I've also done the After Update with and without the '.Requery', it doesn't make a difference.
Does anyone know how to fix this? thanks so much....
Rosie
Jul 30 '07 #1
1 1842
NeoPa
32,556 Expert Mod 16PB
Have you managed to get anywhere with this yet Rosie?
Aug 3 '07 #2

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

Similar topics

4
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...
5
by: Koen | last post by:
Hi all, I created a function that updates a certain status field. The status can be influenced by four different other fields. So, on the form where I edit these fields I call the function (see...
3
by: Jim | last post by:
I am just starting to put together a simple First name, Last name, Address, City/State, Zip, Phone, & etc. database and I have several thousand entries to make, many of which will have the same...
9
by: hope | last post by:
Hi Access 97 I'm lost on this code please can you help ================================= Below is some simple code that will concatenate a single field's value from multiple records into a...
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...
4
by: David | last post by:
Hi, Please can you help me get this code to run ? -------------------- Dim dbs2 As DAO.Database, rst2 As DAO.Recordset, str2 As String Set dbs2 = CurrentDb strtest2 = "SELECT...
5
by: noLoveLusT | last post by:
hi everyone i am very very new to the sql server (2 days actually and ) so far i learned creating SPs etc but couldnt workout how to get return value from my prodecure my sp as follows...
47
by: Jo | last post by:
Hi there, I'm Jo and it's the first time I've posted here. I'm in process of creating a database at work and have come a little unstuck.....I'm a bit of a novice and wondered if anyone could...
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,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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...
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
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
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...
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.