473,385 Members | 1,506 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.

Imported tables with autonumber errors

imrosie
222 100+
Hello all,

My Customer table with Autonumbers used as the customer account number. There are two main forms (Order frm, Customer frm); the Customer's account number displays in a bound control on each. All relationships are tied to this account number, it's an Order entry system. The trouble comes in after adding a new customer.

there's a combo control on Customer frm to search a name and if not found, the NotInList function is triggered. The acct number' control is the second control on the Customer frm. Once a new person is successfully added to the table an autonumber 'acct number' is assigned. However, what I've discovered is that somehow, the person is getting 2, 3 autonumbers...and I don't know how this is happening. I found this out when I had difficulty on the Order frm trying to bring up the newly added customer. I couldn't locate the new customer through the combo box on the Order form. So I went into the actual table and found that my newly added (Joe Smoe, acct# 2442) had 2 and sometimes 3 autonumbers (2442, 2443),...I had to delete one of the numbers, in order to bring up the new name. As soon as I have to add another pperson, the same thing all over again. On the Order form, if I make the 'acct number' control unbound, the assigned nnumber from the customer form doesn't come up when you bring up a customers record, only when you make it bound, BUT then, you're assigning again, the customer another number. Help, help

What a mess. I need to maintain the integrity between the imported tables so I don't lose the existing customer info (re: past order history). Does anyone have ideas how to alleviate this? Unfortunately the Customer table (and some of my other tables) were imported with autonumbers already used as Primary Keys).
There are over 2300 Customer existing records so I can't start all over. I tried on a test DB, doing an append query to get the old info into a new db, but lost all the relationships because of new autonumbers.....Help,
anyone? thanks in advance
Here's the 'NotInList' event (if that's the issue??)
Expand|Select|Wrap|Line Numbers
  1. Private Sub customername_NotInList(NewData As String, Response Dim strSQL As String
  2. Dim FirstName As String
  3. Dim LastName As String
  4. Dim i As Integer
  5. Dim SpacePosition As Integer
  6. Dim Msg As String
  7. SpacePosition = InStr(NewData, " ")
  8.  
  9.     'Exit this sub if the combo box is cleared
  10.     If NewData = "" Then Exit Sub
  11.  
  12.     Msg = "'The name," & NewData & "' is not found." & vbCr & vbCr
  13.     Msg = Msg & "Do you want to add new customer?"
  14.  
  15. FirstName = Trim(Left(NewData, SpacePosition - 1))
  16.    LastName = Trim(Mid(NewData, SpacePosition + 1))
  17.  
  18.     i = MsgBox(Msg, vbQuestion + vbYesNo, "New Customer Name...")
  19.     If i = vbYes Then
  20.         strSQL = "Insert Into Customers ([FirstName], [LastName]) " & _
  21.     "values ('" & FirstName & "','" & LastName & "');"
  22.         CurrentDb.Execute strSQL, dbFailOnError
  23.         Response = acDataErrAdded
  24.     Else
  25.         Response = acDataErrContinue
  26.     End If
  27.  
  28. End SubAs Integer)
  29.  
  30.  
Rosie
Aug 23 '07 #1
7 1634
FishVal
2,653 Expert 2GB
Hello all,

My Customer table with Autonumbers used as the customer account number. There are two main forms (Order frm, Customer frm); the Customer's account number displays in a bound control on each. All relationships are tied to this account number, it's an Order entry system. The trouble comes in after adding a new customer.

there's a combo control on Customer frm to search a name and if not found, the NotInList function is triggered. The acct number' control is the second control on the Customer frm. Once a new person is successfully added to the table an autonumber 'acct number' is assigned. However, what I've discovered is that somehow, the person is getting 2, 3 autonumbers...and I don't know how this is happening. I found this out when I had difficulty on the Order frm trying to bring up the newly added customer. I couldn't locate the new customer through the combo box on the Order form. So I went into the actual table and found that my newly added (Joe Smoe, acct# 2442) had 2 and sometimes 3 autonumbers (2442, 2443),...I had to delete one of the numbers, in order to bring up the new name. As soon as I have to add another pperson, the same thing all over again. On the Order form, if I make the 'acct number' control unbound, the assigned nnumber from the customer form doesn't come up when you bring up a customers record, only when you make it bound, BUT then, you're assigning again, the customer another number. Help, help

What a mess. I need to maintain the integrity between the imported tables so I don't lose the existing customer info (re: past order history). Does anyone have ideas how to alleviate this? Unfortunately the Customer table (and some of my other tables) were imported with autonumbers already used as Primary Keys).
There are over 2300 Customer existing records so I can't start all over. I tried on a test DB, doing an append query to get the old info into a new db, but lost all the relationships because of new autonumbers.....Help,
anyone? thanks in advance
Here's the 'NotInList' event (if that's the issue??)
Expand|Select|Wrap|Line Numbers
  1. Private Sub customername_NotInList(NewData As String, Response Dim strSQL As String
  2. Dim FirstName As String
  3. Dim LastName As String
  4. Dim i As Integer
  5. Dim SpacePosition As Integer
  6. Dim Msg As String
  7. SpacePosition = InStr(NewData, " ")
  8.  
  9.     'Exit this sub if the combo box is cleared
  10.     If NewData = "" Then Exit Sub
  11.  
  12.     Msg = "'The name," & NewData & "' is not found." & vbCr & vbCr
  13.     Msg = Msg & "Do you want to add new customer?"
  14.  
  15. FirstName = Trim(Left(NewData, SpacePosition - 1))
  16.    LastName = Trim(Mid(NewData, SpacePosition + 1))
  17.  
  18.     i = MsgBox(Msg, vbQuestion + vbYesNo, "New Customer Name...")
  19.     If i = vbYes Then
  20.         strSQL = "Insert Into Customers ([FirstName], [LastName]) " & _
  21.     "values ('" & FirstName & "','" & LastName & "');"
  22.         CurrentDb.Execute strSQL, dbFailOnError
  23.         Response = acDataErrAdded
  24.     Else
  25.         Response = acDataErrContinue
  26.     End If
  27.  
  28. End SubAs Integer)
  29.  
  30.  
Rosie
Hi, Rosie.

Plz, post additional information concerning combobox "customername"
  • RowSource - if it is table post table metadata, if it is a query post SQL, if the query based on another query post SQL of latter query and so on
  • BoundColumn
  • ColumnWidths
  • ColumnCount
Aug 23 '07 #2
imrosie
222 100+
Hi, Rosie.

Plz, post additional information concerning combobox "customername"
  • RowSource - if it is table post table metadata, if it is a query post SQL, if the query based on another query post SQL of latter query and so on
  • BoundColumn
  • ColumnWidths
  • ColumnCount
FishVal,

Hopefully the following will help....I've been digging through the code and I think my problem with the Order form is this....it's based on a query called qryOrderSource:

Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCTROW Orders.OrderID, Orders.CustomerID, Orders.EmployeeID, Customers.FirstName, Customers.LastName, Orders.OrderDate, Orders.ShipDate, Orders.FreightCharge, Orders.ShipName, Orders.ShipAddress, Orders.ShipCity, Orders.ShipStateOrProvince, Orders.ShipZIPCode, Orders.ShipCountry, Customers.CompanyName, Customers.BillingAddress, Customers.City, Customers.StateOrProvince, Customers.ZIPCode, Customers.Country, Customers.ContactTitle, Orders.ShipPhoneNumber, Orders.ShipFaxNumber, Orders.PurchaseOrderNumber, Customers.Notes
  2. FROM Customers INNER JOIN Orders ON Customers.CustomerID = Orders.CustomerID;
I think the'inner join' is preventing my being able to bring up a new customer on the Order form because the new customer ......simply doesn't have an order yet.
Maybe I'm wrong...don't know. I have no problem bring up an existing customer that has ordered before.

The combo box is unbound on both the Order Form and on the Customer Form.
Here's the source control:
Expand|Select|Wrap|Line Numbers
  1. SELECT Customers.CustomerID, [FirstName] & " " & [LastName] FROM Customers ORDER BY [FirstName] & "," & [LastName]; 
As for the Customer form (with customername control)....I believe now that the customername (the first control encountered) when the form refreshes (OnCurrent()). If so, all the other controls in the form are still blank. Hence your VBA is adding a record with only the customername populated. After hitting <Enter> after the last field, you're again adding a record, this time with all fields populated.

I"m trying to figure out how verify that I want to keep the NewData in the combobox, not to add a record in the NotInList() event. I need to set my Response to either Added or Continue, the same as at the end of the routine.

If I can figure this out, I think it will fix both forms. Does this help? thanks so much.
Rosie
Aug 23 '07 #3
FishVal
2,653 Expert 2GB
Hi, Rosie.

The problem with NotInList event is that your combobox RowSource is not updated after a new customer has been added to the customers table.
This may cause multiple entering of the same customer until the form is not reopened.

To tell the truth I would do it via ADO.Recordset. In the following example I replaced update via SQL with update via Recordset, added combo requery, and make some not critical changes to the rest of the code.
Expand|Select|Wrap|Line Numbers
  1. Private Sub customername_NotInList(NewData As String, Response As Integer)
  2.  
  3.     Dim strSQL As String
  4.     Dim FirstName As String
  5.     Dim LastName As String
  6.     Dim Msg As String
  7.     Dim RS As New ADODB.Recordset
  8.  
  9.     'Exit this sub if the combo box is cleared
  10.     If NewData = "" Then Exit Sub
  11.  
  12.     Msg = "'The name," & NewData & "' is not found." & vbCr & vbCr
  13.     Msg = Msg & "Do you want to add new customer?"
  14.  
  15.     FirstName = Trim(Split(NewData, " ")(0))
  16.     LastName = Trim(Split(NewData, " ")(0))
  17.  
  18.     Response = acDataErrContinue
  19.     If (MsgBox(Msg, vbQuestion + vbYesNo, "New Customer Name...")) = vbNo Then Exit Sub
  20.  
  21.         Response = acDataErrAdded
  22.  
  23.     With RS
  24.          .Open "Customers", CurrentProject.Connection, _
  25.             adOpenDynamic, adLockOptimistic
  26.         .AddNew
  27.         ![FirstName] = FirstName
  28.         ![LastName] = LastName
  29.         .Update
  30.         Me.customername = ![CustomerID]
  31.         .Close
  32.     End With
  33.  
  34.     Me.customername.Requery
  35.  
  36.     Set RS = Nothing
  37.  
  38. End Sub
  39.  
Aug 23 '07 #4
imrosie
222 100+
Hi, Rosie.

The problem with NotInList event is that your combobox RowSource is not updated after a new customer has been added to the customers table.
This may cause multiple entering of the same customer until the form is not reopened.

To tell the truth I would do it via ADO.Recordset. In the following example I replaced update via SQL with update via Recordset, added combo requery, and make some not critical changes to the rest of the code.
Expand|Select|Wrap|Line Numbers
  1. Private Sub customername_NotInList(NewData As String, Response As Integer)
  2.  
  3.     Dim strSQL As String
  4.     Dim FirstName As String
  5.     Dim LastName As String
  6.     Dim Msg As String
  7.     Dim RS As New ADODB.Recordset
  8.  
  9.     'Exit this sub if the combo box is cleared
  10.     If NewData = "" Then Exit Sub
  11.  
  12.     Msg = "'The name," & NewData & "' is not found." & vbCr & vbCr
  13.     Msg = Msg & "Do you want to add new customer?"
  14.  
  15.     FirstName = Trim(Split(NewData, " ")(0))
  16.     LastName = Trim(Split(NewData, " ")(0))
  17.  
  18.     Response = acDataErrContinue
  19.     If (MsgBox(Msg, vbQuestion + vbYesNo, "New Customer Name...")) = vbNo Then Exit Sub
  20.  
  21.         Response = acDataErrAdded
  22.  
  23.     With RS
  24.          .Open "Customers", CurrentProject.Connection, _
  25.             adOpenDynamic, adLockOptimistic
  26.         .AddNew
  27.         ![FirstName] = FirstName
  28.         ![LastName] = LastName
  29.         .Update
  30.         Me.customername = ![CustomerID]
  31.         .Close
  32.     End With
  33.  
  34.     Me.customername.Requery
  35.  
  36.     Set RS = Nothing
  37.  
  38. End Sub
  39.  
Hi FishVal,
I looked it over and copy/pasted it as a replacement to my code. However, the result is not what I think was expected. If I typed in the combo box the name "Salty Pretzel",,,,,the result in the window was Salty, Salty, I think because you had O and O on the trim statements, so it repeated the FirstName portion.....I didn't quite understand the "With RS" (recordset) portion, so I put back in the following to get the parsing to work:

Expand|Select|Wrap|Line Numbers
  1. Private Sub customername_NotInList(NewData As String, Response As Integer)
  2. Private Sub customername_NotInList(NewData As String, Response As Integer)
  3.     Dim strSQL As String
  4.     Dim FirstName As String
  5.     Dim LastName As String
  6.     Dim Msg As String
  7.     SpacePosition = InStr(NewData, " ")
  8.  
  9.     Dim RS As New ADODB.Recordset
  10.  
  11.     'Exit this sub if the combo box is cleared
  12.     If NewData = "" Then Exit Sub
  13.  
  14.     Msg = "'The name," & NewData & "' is not found." & vbCr & vbCr
  15.     Msg = Msg & "Do you want to add new customer?"
  16.  
  17.    FirstName = Trim(Left(NewData, SpacePosition - 1))
  18.    LastName = Trim(Mid(NewData, SpacePosition + 1))
  19.     'FirstName = Trim(Split(NewData, " ")(0))
  20.     'LastName = Trim(Split(NewData, " ")(0))
  21.  
  22.     Response = acDataErrContinue
  23.     If (MsgBox(Msg, vbQuestion + vbYesNo, "New Customer Name...")) = vbNo Then Exit Sub
  24.  
  25.         Response = acDataErrAdded
  26.  
  27.     With RS
  28.          .Open "Customers", CurrentProject.Connection, _
  29.             adOpenDynamic, adLockOptimistic
  30.         .AddNew
  31.         ![FirstName] = FirstName
  32.         ![LastName] = LastName
  33.         .Update
  34.         Me.customername = ![CustomerID]
  35.         .Close
  36.     End With
  37.  
  38.     Me.customername.Requery
  39.  
  40.     Set RS = Nothing
  41.  
  42. End Sub
  43.  
Any comments....?? thanks
Aug 25 '07 #5
FishVal
2,653 Expert 2GB
Hi, Rosie.
  • You are right - subscripts in "Split" should be 0 and 1. Actually these are subscripts of substrings array "Split" function returns.
  • Below is commented part of the code dealing with ADO
    Expand|Select|Wrap|Line Numbers
    1.     'declares ADO.Recordset object that will be
    2.     'instantiated automatically
    3.     Dim RS As New ADODB.Recordset
    4.  
    5.     '..............................
    6.  
    7.     'calling RS properties/functions
    8.     With RS
    9.         'opens "Customers" table into Recordset RS, using
    10.         'active database ADO connection
    11.         .Open "Customers", CurrentProject.Connection, _
    12.             adOpenDynamic, adLockOptimistic
    13.         'creates new record to the recordset
    14.         .AddNew
    15.         'set values for the fields [FirstName] and [LastName]
    16.         ![FirstName] = FirstName
    17.         ![LastName] = LastName
    18.         'write the record to "Customers table"
    19.         .Update
    20.         'retrieves Autonumber [CustomerID]
    21.         Me.customername = ![CustomerID]
    22.         'closes recordset
    23.         .Close
    24.     End With
    25.  
    26.     Me.customername.Requery
    27.  
    28.     'destroy Recordset object being needed no longer
    29.     Set RS = Nothing
    30.  
    The aim of the code is to retrieve [CustomerID] of a new customer. While it could be done using "INSERT INTO....." and then retrieving [CustomerID] with DMax function, its much more safe to do it via Recordset.

Regards,

Fish

P.S. You didn't say whether is it working or not.
Aug 27 '07 #6
imrosie
222 100+
Hi, Rosie.
  • You are right - subscripts in "Split" should be 0 and 1. Actually these are subscripts of substrings array "Split" function returns.
  • Below is commented part of the code dealing with ADO
    Expand|Select|Wrap|Line Numbers
    1.     'declares ADO.Recordset object that will be
    2.     'instantiated automatically
    3.     Dim RS As New ADODB.Recordset
    4.  
    5.     '..............................
    6.  
    7.     'calling RS properties/functions
    8.     With RS
    9.         'opens "Customers" table into Recordset RS, using
    10.         'active database ADO connection
    11.         .Open "Customers", CurrentProject.Connection, _
    12.             adOpenDynamic, adLockOptimistic
    13.         'creates new record to the recordset
    14.         .AddNew
    15.         'set values for the fields [FirstName] and [LastName]
    16.         ![FirstName] = FirstName
    17.         ![LastName] = LastName
    18.         'write the record to "Customers table"
    19.         .Update
    20.         'retrieves Autonumber [CustomerID]
    21.         Me.customername = ![CustomerID]
    22.         'closes recordset
    23.         .Close
    24.     End With
    25.  
    26.     Me.customername.Requery
    27.  
    28.     'destroy Recordset object being needed no longer
    29.     Set RS = Nothing
    30.  
    The aim of the code is to retrieve [CustomerID] of a new customer. While it could be done using "INSERT INTO....." and then retrieving [CustomerID] with DMax function, its much more safe to do it via Recordset.

Regards,

Fish

P.S. You didn't say whether is it working or not.
I'm sorry,,,,,YES it's working great. thanks so much for your help and insight.
take care.
Rosie
Aug 27 '07 #7
FishVal
2,653 Expert 2GB
I'm sorry,,,,,YES it's working great. thanks so much for your help and insight.
take care.
Rosie
You are welcome.
Fish
Aug 27 '07 #8

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

Similar topics

2
by: Randy | last post by:
I am new to Access and need to link to two tables with a case number. If I link using the Relationship feature will it automatically enter the case number in the child database if I put the case...
11
by: dskillingstad | last post by:
I've been struggling with this problem for some time and have tried multiple solutions with no luck. Let me start with, I'm a novice at Access and I'm not looking for someones help to design my...
17
by: Wilfried | last post by:
Hi, I have 5 tables: main data1
1
by: deko | last post by:
What I'm trying to do is allow advanced users to compose SQL queries to update imported tables - and only imported tables. So I have a table that contains all the internal table names...
25
by: MLH | last post by:
In an earlier post entitled... "A97 closes down each time I open a particular report" it has been suggested that I rebuild problematic table - one in which some corruption has occurred. I...
18
by: DP | last post by:
hi, i'm designing a video and games rental database. i've got the customer table, with all the correct and relavant details. i've got a films, and games table. But i'm confused which way to...
11
by: Alan Mailer | last post by:
A project I'm working on is going to use VB6 as a front end. The back end is going to be pre-existing MS Access 2002 database tables which already have records in them *but do not have any...
7
by: tfoale | last post by:
Hi. I'm a newbie trying to modify imported files in VBA (Access 2003) and struggling with it. I have a set of large CSV files (too large to handle in Excel) each containing data related to a...
3
by: BASSPU03 | last post by:
(I'm using Access 2003 on a Windows XP O/S.) I have four tables that are related in the following order: tblFiscalYear > tblBulkObligations > tblProjects > tblResources These are their...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
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,...
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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 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.