473,396 Members | 1,714 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.

Is it possible to add a value to an existing record

Expand|Select|Wrap|Line Numbers
  1. Sub cmbENum_AfterUpdate()
  2.  
  3. DoCmd.RunSQL "INSERT INTO tblExa(CCanEnt) SELECT tblCwS.CCanEnt FROM tblCwS WHERE tblCwS.ENum = tblExa.ENum"
  4.  
  5. End Sub
  6.  
Tried that, without success.
When I change the value ENum in a combo box, I want it to take the value of CCanEnt from the same record, and add it to an existing record in another table.
May 1 '07 #1
5 1444
Lysander
344 Expert 100+
Expand|Select|Wrap|Line Numbers
  1. Sub cmbENum_AfterUpdate()
  2.  
  3. DoCmd.RunSQL "INSERT INTO tblExa(CCanEnt) SELECT tblCwS.CCanEnt FROM tblCwS WHERE tblCwS.ENum = tblExa.ENum"
  4.  
  5. End Sub
  6.  
Tried that, without success.
When I change the value ENum in a combo box, I want it to take the value of CCanEnt from the same record, and add it to an existing record in another table.
Your code is picking up ENum from the table, not the form. If you have not saved your record, then the value of ENum from the combo box is not the same as Enum in the table. Try changing your WHERE clause to
WHERE tblCwS.ENum=" & cmbENum
May 1 '07 #2
Expand|Select|Wrap|Line Numbers
  1.  DoCmd.RunSQL "INSERT INTO tblExa(CCanEnt) SELECT " & txtCCanENt & " FROM tblCwS WHERE tblCwS.ENum = " & cmbENum
  2.  
Data type Mismatch In Criteria Expression
Does that mean the value Im trying to insert isn't valid for that field?
May 1 '07 #3
It's because it's trying to add a whole new record to the table, and I've set tblExa up to not allow duplicate records. I need the value of CCanEnt to add itself to the record where ENum in tblCwS is the same as ENum in tblExa.
May 1 '07 #4
Lysander
344 Expert 100+
It's because it's trying to add a whole new record to the table, and I've set tblExa up to not allow duplicate records. I need the value of CCanEnt to add itself to the record where ENum in tblCwS is the same as ENum in tblExa.
Instead of insert, you want update, like this
Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL "UPDATE  tblCwS SET CCanEnt='" & txtCCanENt & "' WHERE ENum =" & cmbENum & ";"
  2.  
I'm not sure exactly which table you are trying to update, also, note the apostrophe before and after the quotes to make a string out of txtCCanENt
May 1 '07 #5
Thanks! working great. You forgot to enclose the second variable in single quotes but it was easy enough to fix
May 2 '07 #6

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

Similar topics

2
by: Chris | last post by:
I have tableA, defined as: field1 varchar2(10), field2 varchar2(10), field3 varchar2(10) I have host variables defined as: v1 pic x(10) varying v2 pic x(10) varying
6
by: allyn44 | last post by:
HI--what I am trying to do is 2 things: 1. Open a form in either data entry mode or edit mode depending on what task the user is performing 2. Cancel events tied to fields on the form if I am in...
3
by: Chris | last post by:
Before I started to create table, etc to track unique form field record number assigments I thought I'd check to see if there is now a better way to do this in .NET. I have a parent form (table)...
21
by: planetthoughtful | last post by:
Hi All, As always, my posts come with a 'Warning: Newbie lies ahead!' disclaimer... I'm wondering if it's possible, using raw_input(), to provide a 'default' value with the prompt? I would...
5
by: Phil Latio | last post by:
I have 2 virtually identical tables and wish to move data between them. Basically one table is called "live_table" and the other is named "suspended_table" and the only difference is that the...
6
by: carmela_wong | last post by:
Hello all, I am trying to set the default value of a combo box to "USA" which does not work although I have entered this in the Default Value property of the control. The combo box shows the...
15
by: scparker | last post by:
I have yet to find a satisfactory solution to this problem. It involves VB.NET 2.0 and datetime issues. I have a form that asks for a Date to be submitted in dd/mm/yyyy format. When this is...
5
by: =?Utf-8?B?bWNhdWxpZmZl?= | last post by:
I have an old application ( pre-VB5) that I need to add a select/option list to. This is an edit program so the values for the form will be retrieved from a database. How do I set the value of...
17
geolemon
by: geolemon | last post by:
This should be an easy one for anyone with basic forms experience (I'd hate for you guys to be bored!) :D I have a simple form, bound to a single table. I'd *like* the form to work this way:...
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: 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
Oralloy
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,...
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...
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...
0
agi2029
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,...

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.