Microsoft Access Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft Access Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old November 11th, 2003, 08:38 AM
wynbryant wynbryant is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 2 wynbryant User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 52 sec
Reputation Power: 0
Track Changes in DB

I'm looking for suggestions as to the best way to implement a "record change event log." I'd like to store the value of a particular field or fields if it is changed (by means of a Form). Please see table structure below.

tbl_Membership:
pk: rec_ID
fname
lname
addr1
addr2
etc...

tbl_Mbr_Changes:
fk: rec_ID
changed_field
changed_value
timestamp
user

I'm assuming I would need to use the OnCurrent event to append the current record to a temporary table (to store initial values) and go from there. I'm confused on what to do next. Should I have an OnChange event for each field? Seems like there would have to be a better way. Any help appreciated.

Wyn Bryant

Reply With Quote
  #2  
Old November 11th, 2003, 11:59 AM
sbaxter sbaxter is offline
Moderator: Access, SQL
ASP Free God (5000 - 5499 posts)
 
Join Date: Oct 2003
Posts: 5,126 sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 1 h 2 m 51 sec
Reputation Power: 12
Are you using Bound or UnBound Forms and Text boxes?

S-

Reply With Quote
  #3  
Old November 11th, 2003, 12:42 PM
wynbryant wynbryant is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 2 wynbryant User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 52 sec
Reputation Power: 0
S-

This particular form is bounded. I was able to figure out how to store the value before change, but my code is very inefficient. I have several AfterUpdate() events (one for each field) that all run basically the same SQL append with the only change being the field name. How would I structure a function call with the variable being the field name?

Here are my current AfterUpdate() events:

Code:
Private Sub tb_[FIELDNAME]_AfterUpdate()

DoCmd.RunSQL "INSERT INTO t_Membership_Changes ( rec_id, field, changedval, changed_by, [timestamp] ) SELECT rec_id, [FIELDNAME] AS Expr1, t_Membership_CurRec.[FIELDNAME] AS Expr2, fOSUserName AS Expr3, Now() AS Expr4;"

End Sub



How would I reference the FIELDNAME variable?

Reply With Quote
  #4  
Old November 11th, 2003, 01:54 PM
sbaxter sbaxter is offline
Moderator: Access, SQL
ASP Free God (5000 - 5499 posts)
 
Join Date: Oct 2003
Posts: 5,126 sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 1 h 2 m 51 sec
Reputation Power: 12
Here is two suggestions:

1. (My personnal perference) You seem familar with unbound forms, so don't use bounded ones. Use a unbounded form that everytime you hit a update button, it creates your adds the records to you history table as part of the action of editing the record

2. In the after_update event of each field change a "FieldchangeVariable" from False to true (different one for each field) that will state a change has taken place with this field. then don't use the form controls for moving from record to record, create buttons that do this so when the move to another record you look to see which field have changed (based on the FieldchangeVariable) and pass through you SQL where each variable is set to true. WHen done set all variables to false for next record. This will only record the last change to that field for each record.


As far as "How would I structure a function call with the variable being the field name"

VariableOne = "FieldName"

DoCmd.RunSQL "INSERT INTO t_Membership_Changes ( rec_id, field, changedval, changed_by, [timestamp] )

SELECT rec_id, " & VariableOne & " AS Expr1,

t_Membership_CurRec.[FIELDNAME] AS Expr2, fOSUserName AS Expr3, Now() AS Expr4;"


S-

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft Access Help > Track Changes in DB


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway