473,406 Members | 2,467 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,406 software developers and data experts.

Append query with criteria

robin a
30
Hi,
I have an append query that has to add a record to a table [Join_tbl] if the field [ReqUNID] does not exist (there are other fields added as well with their own criteria) OR If the [ReqUID] already exists but another field [TaskStatus] has changed, then overwrite the [TaskStatus] field only. This is the code I have that only adds a record if the [ReqUID] doesn't exist.
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO Join_tbl
  2.    ( ReqUNID, 
  3.       TaskTeam, 
  4.       TaskAssignee, 
  5.       taskStatus )
  6. SELECT dbo_vwAssignments.ReqUNID, 
  7.    dbo_vwAssignments.TaskTeam, 
  8.    dbo_vwAssignments.TaskAssignee, 
  9.    dbo_vwAssignments.taskStatus
  10. FROM dbo_vwAssignments
  11. WHERE (
  12.    ((dbo_vwAssignments.TaskTeam)
  13.       ="chp-vm")
  14.     AND ((dbo_vwAssignments.taskStatus)
  15.            ="acknowledged" 
  16.          Or (dbo_vwAssignments.taskStatus)
  17.               ="new" 
  18.          Or (dbo_vwAssignments.taskStatus)
  19.               ="pending" 
  20.          Or (dbo_vwAssignments.taskStatus) Is Null));
Thank you in advance for your help
Dec 13 '12 #1
7 3932
Rabbit
12,516 Expert Mod 8TB
You will need two querys. An append query and an update query. I don't think you can do it with just one query in Access.
Dec 13 '12 #2
robin a
30
thank you, i did get to that point after i asked for help. You are quick, (Rabbit). I built the queries but for some reason my update query makes the data in the field to be updated blank. This is my update query:
Expand|Select|Wrap|Line Numbers
  1. UPDATE Temp_Join_tbl
  2.    INNER JOIN Join_tbl 
  3.       ON Temp_Join_tbl.ReqUNID 
  4.          = Join_tbl.ReqUNID 
  5. SET Join_tbl.ReqUNID 
  6.       = [Temp_Join_tbl].[ReqUNID], 
  7.    Join_tbl.Status 
  8.       = [Temp_Join_tbl].[Status]
  9. WHERE (
  10.    ((Join_tbl.ReqUNID)
  11.          =[Join_tbl].[ReqUNID])
  12. );
I'm trying to update the Join_tbl.[status] with the value in Temp_Join_tbl.[Status] WHERE Temp_Join_tbl.ReqUNID = Join_tbl.ReqUNID SET Join_tbl.ReqUNID

Any suggestion?
Dec 13 '12 #3
robin a
30
sorry, i since removed the ReqUID field from the query and it works fine, but I don't understand why.
Dec 13 '12 #4
NeoPa
32,556 Expert Mod 16PB
Rabbit:
You will need two querys. An append query and an update query. I don't think you can do it with just one query in Access.
Until quite recently I would have agreed with that. It turns out however, that an UPDATE query will act as an APPEND query in Access (Jet) when no match existing record is found.
Dec 13 '12 #5
NeoPa
32,556 Expert Mod 16PB
Robin:
sorry, i since removed the ReqUID field from the query and it works fine, but I don't understand why.
If you were trying to set an AutoNumber value from another table then it would fail. AutoNumber values can only ever be set explicitly within an APPEND action. When you removed the code to set that the query could work.
Dec 13 '12 #6
zmbd
5,501 Expert Mod 4TB
Post #3 Codeblock-Line 10: The WHERE clause with the SQL refers to the same table and same field; However, this is not as indicated in the sentence following wherein that statement refers to the fields between the two tables.

If the [ReqUID] is an autonumber it should have erred, not cleared fields.
Dec 14 '12 #7
NeoPa
32,556 Expert Mod 16PB
Z:
If the [ReqUID] is an autonumber it should have erred, not cleared fields.
Good spot. I didn't see (overlooked) that detail :-(

So was the spot of the error in the OP's WHERE clause. Sharp today Z :-)
Dec 14 '12 #8

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

Similar topics

7
by: | last post by:
I found similiar issues in MS-KB but nothing that helped me; got the Windows and Office updates from the MS website but that hasn't changed the behavior of this problem, and I don't see anything...
2
by: Ray Holtz | last post by:
I have a form that shows a single record based on a query criteria. When I click a button it is set to use an append query to copy that record to a separate table, then deletes the record from the...
1
by: jpr | last post by:
Friends, I would like some help with a code that allows me to run an append query only if a specific field is not already stored into another table. Example. I add a new customer to my database...
4
by: pmacdiddie | last post by:
I have an append query that needs to run every time a line item is added to a subform. The append writes to a table that is the source for a pull down box. Problem is that it takes 5 seconds to...
0
by: jon | last post by:
Hi there, I'm brand new to Access and may be trying to do too much too soon, but I wanted to get some expert advice on how the best way to go about what I am trying to accomplish would be. I...
11
by: kabradley | last post by:
Hello Everyone, So, thanks to nico's help I was finally able to 'finish' our companies access database. For the past week or so though,I have been designing forms that contain a subform and an...
1
by: Sailor7 | last post by:
The problem I am having is setting up some code to query a table(Tbl_Table1_ContainsLotsOfData) using criteria in another table(Tbl_Table2_ContainsCriteria), then appending the result to an...
2
by: ilikebirds | last post by:
In 1 Database(ttt) I currently have a Union Query that collects data from 4 databases (a,b,c,d) and then a MakeTable query that combines all of those into a table. ( Union A,B,C,D to make table in...
5
by: brandon Gadish | last post by:
I am trying to append a table with records from another table. When I run the Append query the first time it works fine, however when I run it a second time it will duplicate the records. I created...
4
by: Adam Tippelt | last post by:
Situation: When a user 'confirms' that they want to save the information they've inputted, I need to append the database records from a temporary table to a different table. Problem: The...
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: 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...
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
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
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.