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

tracking data edits across different tables

Hi everyone,

Firstly I am using access 2007. I currently have 2 tables in my database, 1 to store up to date data and the other to store out of date data (where data edits have been made, for audit purposes). I have set up a one-to-many relation ship between the 2 tables based on the record number.

I use a form to search for records which opens up a split form to show all of the matching records. I do have a code which selects and copies the old data before it is replaced, it is then replaced and the code then pastes the old record into the second table. (the macro is posted below N.B. it was written in access 2007's macro builder window).

My problem is that the record that is copied and pasted is always the first record in the database not necessarily the record being edited. Can anyone help (I feel that the solution is quite simple and I have tried various different solutions but I can't quite get the right solution (the macro posted is my best attempt so far).

Expand|Select|Wrap|Line Numbers
  1. On Error          Next,
  2. OpenTable         CD Signatures, Datasheet, Edit
  3. RunCommand        SelectRecord
  4. RunCommand        Copy
  5. RunCommand        Replace
  6. RunCommand        Refresh
  7. OpenTable         Edited Signatures, Datasheet, Edit
  8. GoToRecord        Table, Edited Signatures, New
  9. RunCommand        SelectRecord
  10. RunCommand        Paste
  11. Close             Table, CD Signatures, Yes
  12. Close             Table, Edited Signatures, Yes
  13. RunCommand        Refresh
Jan 4 '13 #1
13 2252
TheSmileyCoder
2,322 Expert Mod 2GB
I don't really work with the macros of Access. I don't feel they are flexible enough to work to my needs.

My approach is as so:
In the beforeUpdate event I copy the record using SQL, not Copy/Paste. This requires the record has a unique key.

If you are interested I can find the code for you, but it is not something you can simply copy and paste, you will need to make the required code modifications yourself. If you are not comfortable doing so, I won't confuse you with codes at this point.

Best of luck with your project
TheSmileyCoder
Jan 4 '13 #2
That sounds like an intriguing idea, I am happy to give any suggestion a go. I have got a backup available if I mess things up. Your help would be really appreciated.
Jan 4 '13 #3
NeoPa
32,556 Expert Mod 16PB
ANewUser:
I have got a backup available if I mess things up.
That's very sensible :-)

I would echo what Smiley's said already. I would ask though, for you to post the data layout of your tables. The general data is not too important, but the indexing for each is very important to know. Bear in mind that while the primary table must have unique records based on a specific PK, the archive table needs the primary PK (IE. of the primary table) to allow duplicates as a record may be archived more than once. I would expect the PK of the archive to be something like a compound index including the PK of the primary table along with a Date/Time field that stamps when the particular archive record was added.
Jan 4 '13 #4
You are right NeoPa, the archive table does not have a primary key as it does allow for multiple data edits and does have a date/time stamp setup to record when data is added to it. The primary table does use a primary key. I believe what you are asking for is a list of the fields of each table (I am sorry if I am wrong).

Primary table:
Record Number (PK) AutoNumber
Designation Text
First Name Text
Surname Text
Ward Text
Signature OLE Object
Renewal Date Date/Time
Authorised By Text
Date of Last Amendment Date/Time
Added By Text
Changed By Text
Deleted By Text
Restored By Text

Please note that the fields in the archive table are exactly the same (excluding the record number field which is just a number field and does not have a primary key).
Jan 5 '13 #5
NeoPa
32,556 Expert Mod 16PB
That's nearly what I was asking for, but it doesn't include the important parts from the Archive table. Please list how the Record Number and Time Stamp fields are named. When I have that info I will certainly be suggesting, as a first step, that the two fields, together, be defined as a (composite) PK for this table.

Presumably, the task you are trying to achieve is to make a timestamped copy of the currently selected record from the Primary table into the Archive table. What is not clear is how this is (should be) triggered. Is it automatic when an update is applied? Does it happen after a button is clicked?
Jan 6 '13 #6
The date/time stamp is applied at the time the record is created in the primary table by setting a default value of Now() in the "Date of last amendment" field. When the data is archived this value remains the same for the archived record and a new date/time stamp is applied to the updated record. There is a button which is clicked to apply the change.

However, the problem that I am having is that my macro is only selecting the first record in the primary table and moving it to the archive table regardless of the data being editted.

The record number field is just called record number, it is a number field so that records can be archived more than once.

I hope this helps.
Jan 7 '13 #7
NeoPa
32,556 Expert Mod 16PB
ANewUser:
I hope this helps.
A little, but not a lot.

You need to read my last post again with more attention. You haven't dealt with two important issues raised. It seems sort of pointless for me to raise issues if you don't deal with them. I certainly can't help further, at this stage, as anything further depends on those two points, as well as being a little pointless for me to proceed further if you skip over much of what I say.
  1. Handle the design of the Archive such that it has a PK as indicated (and post to say as much).
  2. Answer the question about triggering of the process.

When we're back up-to-date we can proceed sensibly.
Jan 7 '13 #8
Hi I am sorry it has been a while since my last reply. I have now created a composite PK on my archive table. It took me a little while to find out how to do this which the reason for the delayed reponse.

The event is triggered by clicking on a button called "Update Record" on a split form which shows a list of matching records found by a search form. Edits to the data are made on the form and then the user clicks the button to apply the change and archive the old record.
Jan 9 '13 #9
NeoPa
32,556 Expert Mod 16PB
Excellent. I may need some help understanding all you've said, but this is certainly a response I can proceed from and with.
ANewUser:
Hi I am sorry it has been a while since my last reply. I have now created a composite PK on my archive table. It took me a little while to find out how to do this which the reason for the delayed reponse.
No worries. I wasn't getting bored ;-) And well done. If that wasn't something you knew then you've learned something to take you forward.
ANewUser:
The event is triggered by clicking on a button called "Update Record" on a split form which shows a list of matching records found by a search form. Edits to the data are made on the form and then the user clicks the button to apply the change and archive the old record.
Well done for explaining all this. Unfortunately, although you refer to applying the change, it seems there is the potential for many changes. It also seems, from your wording, that these changes may pertain to multiple records at the same time. If so, this would tend to complicate matters a lot. I don't say it would make it impossible, but it would certainly make it extra difficult for one of your experience to deal with, even with help. Can you clarify the position here do you think.
Jan 9 '13 #10
To clarify the data edits should only be made to to the record currently being viewed in the main body of the form. The reason for the split form is so that the user can select the appropriate record.

I do, however, realise the weakness here the macro (I believe) will only work for the record that is currently being viewed. If the data is editted in the part of the form which shows all of the matching records then the old record(s) will not be archived. This is something I am looking into but I have not yet found a solution).
Jan 10 '13 #11
NeoPa
32,556 Expert Mod 16PB
ANewUser:
To clarify, the data edits should only be made to to the record currently being viewed in the main body of the form. The reason for the split form is so that the user can select the appropriate record.
This comment makes sense. What I find worrying is the other paragraph which talks about edits being made to multiple records in that section of the form which you have just identified as being there only to select the record to work on. In my mind this would make more sense if this section of the form were set as Read Only. Alternatively, a more standard approach would be to use Cascaded Form Filtering with ComboBoxes that contain data from all the matching records and allow you to select any one of them. I really believe this would suit your requirements a lot better and be very easy for the operators to get familiar with.

If you can confirm how you plan to proceed on this point, I think we'll be ready to start looking at the code to handle the logging of your changes.
Jan 10 '13 #12
Hi NeoPa, I have decided to go with the read only route on my existing form and I have formatted it as such.

Thanks for your help so far it is much appreciated
Jan 17 '13 #13
NeoPa
32,556 Expert Mod 16PB
Sorry for the long absence. I haven't forgotten you, but I'm afraid I only have time, at the moment, for more basic, in and out quickly, questions for now. I will look at this again in ernest when I can. It's still stiing in my browser until I can do so.

OK. Let's get the ball rolling anyway.

I don't see where you have ended up with an archive table which has a composite PK. Have you got that sorted out yet?
Jan 23 '13 #14

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

Similar topics

4
by: John | last post by:
Hello. I am just wondering if someone can help me with my PHP/MySql code as I am not too proficient with it yet. What I am wanting to do, is display data from two tables. The first table is...
9
by: Hi5 | last post by:
Hi, Any Idea how, I can make an Insert statement to insert data into 6 different tables, that are all holding all data of my database? Is there any example? I would be grateful if you could...
13
by: MLH | last post by:
I have tblVehicles, tblOwners, tblProxies, tblLienholders. In the vehicles table are and identifying owner and proxy (generally an attorney). Vehicles table is child table to tblOwners and...
1
by: new214 | last post by:
Hey all, got abit of a problem. Ive got a database where ive got 2 tables. I want to create a command which selects * from table 1 and if the same values are in table2 - it updates otherwise adds. ...
0
by: Jerms | last post by:
Hello all, I've been using this site quite a bit since starting my project and have found it very helpful. I have run into a roadblock though that I cant seem to scrounge up a solution to. I...
11
by: isoquin | last post by:
I have a gigantic database that I had to split across two tables (I'd normally use one, but it hits the max number of items in a table). I built input forms for data entry, which are similarly split...
2
by: Dresse | last post by:
Hello, I am trying to save data to one acces database, but in 2 different tables. I use a bindingnavigator to view, edit, delete, modify my data. Now the data is about recipes, so has alot of...
11
by: jennifersalcido | last post by:
Hello All, I am working with two tables that contain inventory data: 1) INVENTORY contains item_number, description, etc. This data is relatively straight-forward, one record per item_number....
0
by: xwebmaster | last post by:
Hi Please help me solving this query.. I have 3 tables.. comm_propDB ID | User_ID | mls_num -----|---------------|--------------------- 2 | 2 | 5004 3 | 2 ...
6
HaLo2FrEeEk
by: HaLo2FrEeEk | last post by:
I have two different tables which havea different number of columns. One of the tables gets a new row every day and is populated with a st of 4 IDs from another table, along with today's date and an...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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
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: 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...

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.