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

Sometimes it SQL Inserts, Sometimes it doesn't

17
Short version.

I have form that opens a linked form where data is populated automatically based on queries, and some data is entered. When this form closed I have SQL code that writes the various fields into the database, and then closes the form. The original for then recalcs so that the entered data now populated. Works grand...sometimes. Sometimes when you close the form, the data just doesn't write into the database due to a key violation (there's a field in the table that autopopulates so that each record has a unique ID). So you open the form again, re-enter your fields, and then it works. I can't figure out why it doesn't write every time.

Tell me what else I need to provide to help.

Update: Added Code

Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String
  2.  
  3.  
  4. strSQL = "INSERT INTO tblMPR_Price([MPR_ID],[SKU]," & _
  5. "[DeadOld],[DeadNew],[MAPOld],[MAPNew],[InvOld],[InvNew],[Rate],[Cost]) " & _
  6. "VALUES (" & Me.[MPR_ID] & ",'" & Me.[SKU] & _
  7. "','" & Me.[DeadOld] & "','" & Me.[DeadNew] & "','" & Me.[MAPOld] & _
  8. "','" & Me.[MAPNew] & "','" & Me.[InvOld] & "','" & Me.[InvNew] & _
  9. "','" & Me.[Rate] & "','" & Me.[Cost] & "');"
  10.  
  11. DoCmd.RunSQL strSQL
Aug 30 '07 #1
2 1257
jclover
17
I figured out the problem. It was due to the relationship between the tables, with the main table linking to the other table with "one-to-many/Enforce Referential Integrity". I redefined the tables, as a one to one, no enforcing, and it solved it. Everything else runsfine still, but I don't enderstand the root of the problem, only that I fixed it.

Anyone want to take a quick minute to teach me what I did?
Aug 31 '07 #2
Rabbit
12,516 Expert Mod 8TB
It sounds like when you tried to insert the record into the linked table, the record in the main table wasn't saved yet so there was no linked record. Enforcing a relationship will throw up an error if you try to save a linked record without a main record. So I usually toss in a save record before inserting a linked record.
Aug 31 '07 #3

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

Similar topics

6
by: Stephane Dalpe | last post by:
Hi all, I just want to know why when I'm installing jdk sometimes ask me to reboot and sometimes he don't. As part of our installation, we launch the jdk installation if it's not already...
2
by: Robson Reis | last post by:
We have installed a package developed by another company and sometimes (when the server is with a big rate of transactions), we are seeing the following messages in package debug file: ...
3
by: Oasis | last post by:
Hello, I'm new to c#. I have situation where I want to execute a number of insert statements that differ only in a few dynamic values. When I was a Java programmer, I would do this with a...
3
by: Chris Ochs | last post by:
First of all, we are still running sapdb at the moment but are in the process of moving to postgresql, so it seemed a good idea to post this type of question here. In our environment we have...
3
by: deathyam | last post by:
Hi, I have an Excel 97 app in which I'm using SQL INSERTs to insert data into an Access 97 database table. The table structure is as follows: VersionID (PK) (Long) MetricID (PK) (Long)...
2
by: simonZ | last post by:
I create a transaction: sqlTran=sqlConn.BeginTransaction(IsolationLevel.Serializable); Then, I insert some data into report table with sqlCommand object: oCmd = new...
0
by: Benzine | last post by:
I recently rolled out replication on our production server (MS SQL 2000 SP4) and every time a subscriber tries to sync the following always appears in the Merge Agent History: "Downloaded 100...
2
by: Randy Smith | last post by:
Hi, I've got some weird behavior happening within one of the datamappers. It all has to do with inserting a new row, and returning the Id of the row being entered. Here is what the code...
0
by: poe | last post by:
Hello, I have a large database table running on SQL Server 8.0. It currently has nearly 98 million records on it's ways to 125 million. I am doing inserts as quickly as the server can handle it,...
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
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...
1
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...
0
tracyyun
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...
0
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.