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

Run a query to append only the current record to another table

11
I have 2 tables in my database (Assets and AssetMovements).
What I'm trying to achieve is that when the value of the 'Location' field is modified in a record in the 'Assets' table, once the user clicks the save button the record should be saved normally and a copy should be appended to the 'AssetMovements' table.

The problem is that my current query appends all the records in the 'Assets' table to the 'AssetMovements' table. I want only the current record to be appended. Also, I want the query to only run when the value of the Location field is modified.

Below is my VBA code for the button's OnClick event:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunCommand acCmdSaveRecord
  2.  
  3. DoCmd.OpenQuery "AppendQuery"
  4.  
I would appreciate any suggestions.
Thanks.
Feb 12 '13 #1

✓ answered by Seth Schrock

Okay, you just need to add a WHERE clause before the ; that is at the end of your query.
Expand|Select|Wrap|Line Numbers
  1. WHERE ID = Forms!your_form_name!your_control_name
The control name that you need is the control that has the data source of ID.

5 11114
Seth Schrock
2,965 Expert 2GB
Your query needs the WHERE clause to filter it down to the current record. Without seeing your query, it is hard to say more than that. If you could copy and paste the SQL code of your query into here (using <CODE/> tags) we can provide a more specific solution. We would also need to know which field is the primary key field.

I do have an idea for how to only execute your query if the location field was changed, but once again, this is a separate question and needs asked in a separate thread. We can work on the query in this thread as that question matches the thread title.
Feb 12 '13 #2
ephi
11
Hello Seth, here is my query code:
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO AssetMovement ( ID, Location, Condition, AssignedTo, AssetTag )
  2. SELECT Assets.ID, Assets.Location, Assets.Condition, Assets.AssignedTo, Assets.AssetTag
  3. FROM Assets;
  4.  
Thanks
Feb 12 '13 #3
Seth Schrock
2,965 Expert 2GB
Okay, you just need to add a WHERE clause before the ; that is at the end of your query.
Expand|Select|Wrap|Line Numbers
  1. WHERE ID = Forms!your_form_name!your_control_name
The control name that you need is the control that has the data source of ID.
Feb 12 '13 #4
ephi
11
Thank you Seth. The WHERE clause fixed the problem.
I will post the second part of the question ion another thread.
Thanks so much for your assistance.
Feb 12 '13 #5
Seth Schrock
2,965 Expert 2GB
No problem. Glad to help. I will keep a lookout for your new thread and explain my idea there.
Feb 12 '13 #6

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

Similar topics

2
by: Colm O'Hagan | last post by:
Hi there, I having a problem with a database I'm setting up, I would be delighted if someone out there could help. The database I'm setting up is a task register datebase, it will be used to...
6
by: Sven Pran | last post by:
Probably the answer is there just in front of me only awaiting me to discover it, but: 1: I want to build a query that returns all records in one table for which there is no successful "join"...
1
by: tkal2k | last post by:
hi all, i have a quick question. i have a table where we use autonumbers to catergorize it, and another table where we use those autonumbers not as the primary id, but still have them in the...
1
by: Jan | last post by:
I have a table with autoincrement unique ID plus name (required not to be blank) and other fields. I have a list of names in another table and would like to do insert to the name field of the...
0
by: mikewilli | last post by:
Warning:: I am very new to programming, having never had to use VBA before, traditionally i am a SQL/Crystal Reports writer... with that in mind: I am currently writing ar eport to extract data...
1
by: DB03836 | last post by:
I am using a select query to sum 2 fields in another select query, but if their are no records and the first select is empty I get a blank. I would like to get a zero if this happens. is this...
2
by: SJ1000 | last post by:
Hi, I think I have a simple question that I just can't figure out. I want to have a command button on a form (via a macro) run a query to append the data on that form to another table.I want it to...
3
by: KevinC | last post by:
Hi All, I have two tables: tblLicensedPrem and tblLicensedPremHistory (these tables are identical). tblLicensedPrem contains records for licensed premises. Over time details of a licensed...
1
by: chaurous | last post by:
hi guys, i have a problem of building a function and from the result i should append the results to another table. function required: my first idea is query but it is not working. how should...
0
by: Neven Huynh | last post by:
Hi Everyone, Here i my LINQ query to get record in Table Menu with condition are parentID == 0(get root menu) and ID != (parentID list) (which is parent ID list is are id of menu record that have...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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...
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
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,...

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.