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

Append error: table due to key violations

I am trying to insert a record into a table and when i try to do so im getting an append error:

'Database' set 0 field(s) to Null due to a type conversion failure, and it didn't add 1 record(s) to the table due to key violations....etc

what i wanted to do was grab the autonumber (aka Trouble #) along with the date, username, and the string "Ticket Created" and insert it into the table.

my previous problem as discussed in this thread http://bytes.com/topic/access/answer...-sql-statement has been solved already with the use of [ ] around date.

I have the following code for a new record

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command67_Click()
  2. On Error GoTo Err_Command67_Click
  3.  
  4.     DoCmd.GoToRecord , , acNewRec
  5.     'Setting the open date to current date
  6.     date_opened = date
  7.  
  8.     Call sqlstatement2("Ticket Created")
  9.     'Setting the Ticket Status to Open
  10.     Combo46 = "OPEN"
  11.  
  12.     [Forms]![User Problem Log]![Opened_By] = user_name
  13.  
  14.     Me!user.SetFocus
  15.  
  16.     If IsNull(user) Then
  17.  
  18.         Command67.Enabled = False
  19.         'disables the add button if end user is not selected.
  20.         'this is to prevent user from accidentally clicking add
  21.         'button twice which creates two new records.
  22.  
  23.     Else
  24.  
  25.         Command67.Enabled = True 'enable the add button
  26.  
  27.     End If
  28.  
  29. Exit_Command67_Click:
  30.     Exit Sub
  31.  
  32. Err_Command67_Click:
  33.     MsgBox Err.Description
  34.     Resume Exit_Command67_Click
  35.  
  36. End Sub
sqlstatement2 is the following code
trouble_no is a number field
date is a date/time field
user is a string field
notes is a memo field

Expand|Select|Wrap|Line Numbers
  1. Sub sqlstatement2(status As String)
  2.  
  3.     Dim strSQL As String
  4.  
  5.     strSQL = "INSERT INTO usr_problem_list "
  6.     strSQL = strSQL & "(trouble_no, [date], user, notes) "
  7.     strSQL = strSQL & "VALUES (" & Text30.Value & ", '" & Now() & "', '" & user_name & "', '" & status & "');"
  8.  
  9.     DoCmd.RunSQL strSQL
  10.  
this is the code i have for form load
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.  
  3. '********** Setting the form to load waiting for a new ticket to be entered **********
  4. On Error GoTo Err_Command21_Click
  5.  
  6.     DoCmd.GoToRecord , , acNewRec
  7.  
  8.     If IsNull(Text30) Then
  9.         Command58.Enabled = False
  10.     End If
  11.  
  12. Exit_Command21_Click:
  13.     Exit Sub
  14.  
  15. Err_Command21_Click:
  16.     MsgBox Err.Description
  17.     Resume Exit_Command21_Click
  18. '********** Setting the form to load waiting for a new ticket to be entered **********
  19.  
  20. End Sub
now after i click the button, i get the append error.
Jan 17 '12 #1

✓ answered by Rabbit

That error usually means that you're trying to insert a record with the same primary key as another record in the table. I'm going to guess that you made trouble_no the primary key on usr_problem_list. Which means trouble_no must be unique.

2 3722
Rabbit
12,516 Expert Mod 8TB
That error usually means that you're trying to insert a record with the same primary key as another record in the table. I'm going to guess that you made trouble_no the primary key on usr_problem_list. Which means trouble_no must be unique.
Jan 17 '12 #2
im an idiot. i think its pulling the previous record trouble #.

i have to save the ticket first before inserting into table.

i just tried it and it worked with no problems.

sigh, i knew it was something stupid i forgot to do :P

thanks Rabbit!
Jan 17 '12 #3

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

Similar topics

3
by: Jagdip Singh Ajimal | last post by:
I have two tables, appointments and backupappointments. I also have a function getAppointments(theDate DATE) RETURN RECORDSET (which has not been written yet). What I want the function to do is...
3
by: Darin | last post by:
This is something that on the surface seems like it should be simple, but I can't think of a way to do this. I have a table that is a list of "jobs", which users create and use. It has a single...
0
by: oiref | last post by:
Why wont access 2003 generate an import errors table to show rejected data.It shows the normal dialog box and then tells me about the data it wont append to the table but thatis it! thanx anyone
2
by: sj | last post by:
Situation: I have 2 tables, parent table (Invoice) and child table (InvoiceDetails) that is link by InvID in the child. Requirement: Need to do one-time append of information to another table...
11
by: LiDongning | last post by:
I have a situation here: every month there will be a table (with 3200+- entries) that should be appended to a Year-to-Date table. I appended the second month's live table to the accumulative...
2
by: Nick03 | last post by:
I am trying to update data in a datagrid that was generated by a view. I keep getting the error: "table has no primary key". Here is the code that I am using: Dim NewQuantity, NewAmount,...
11
by: KingKen | last post by:
I am trying to export some values from a table in my database to a text file then have these values imported and apprnded to another copy of the same database table the same table in another location...
10
by: hedges98 | last post by:
Hello After spending my morning search for a solution to what I need to do, I am a little stuck on which direction to take. Here is the scenario - I have a database that contains information...
1
by: btoussaint | last post by:
We have two tables in that control some different data. Table one is dbo_ProductModel. Table two is dbo_CustomerInformation. Table three is dbo_WebInformation. I created the form from the...
1
by: Katie Howard | last post by:
Hi, I’m just starting a database that will contain historical data of all the conferences that our employees have attended over the years. I have 3 tables (Employees, Conferences, and the 3rd is...
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:
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: 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...
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
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...

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.