Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 19th, 2011, 07:47 AM
Registered User
 
Join Date: May 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default VBA Access function

need a function to do:

- Loop through all fields in a table (use tabledef) (use any table – tablename should be a parameter for the function)

- There needs to be a timestamp-field which is set on some records and not on others

- For each textfield (only textfields – ignore all others!) check if there are new values (compared between the ones with time-stamp and without ) without time stamp will be first default entry and with time stamps will be updated entry

- If there are new values add the name of the field and the new values to a log-table

- After looping through all textfields and putting the name of the field and the values into the log-table – export the log table to Excel and show it in Excel. (alternatively you can log directly to Excel)


The end result in Excel should look something like this:

Fieldname1
NewValue1
NewValue2
NewValue3

Fieldname2
NewValue1
NewValue2

Fieldname3
NewValue1
 
Old May 19th, 2011, 10:40 AM
Friend of Wrox
 
Join Date: Sep 2010
Posts: 245
Thanks: 5
Thanked 24 Times in 23 Posts
Default

I generally build this into each form to do a audit logging so that change to the desired fields are automatically saved to a log file. It is logged in real time. It is a lot easier to do at the form level that the table level.


If you must do it at the table level then I assume you already have some what to know hte old data so that you know hat has changed. Are you saving each record before it is updated.
Here is some DAO code to get you started:
Microsoft Access: DAO Programming Code Examples

Curious how at the table level you know what fields have changed?
__________________
Boyd Trimmell aka HiTechCoach (.com)
Microsoft Access MVP Alumni 2010-2015
 
Old May 19th, 2011, 10:42 AM
Friend of Wrox
 
Join Date: Sep 2010
Posts: 245
Thanks: 5
Thanked 24 Times in 23 Posts
Default

If you want to see how it is done at form level then cehck out:

Audit Trail
Quote:
This db demonstrates how to set up an audit trail of changes to the data including ID, Field Name, the field value before it was changed, the field value after it was changed, the user who did the change, and the date/time the change was made.
__________________
Boyd Trimmell aka HiTechCoach (.com)
Microsoft Access MVP Alumni 2010-2015
 
Old May 19th, 2011, 10:50 AM
Registered User
 
Join Date: May 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Example:
tblMember
ID Name SurName DOB Address datetimestamp
1 Nirav Mehta 01/12/1978 24 abc street
2 N Mehta 01/12/1978 3433 19/05/2011 12:00:00
3 N M 01/12/1978 3434 19/05/2011 14:00:00
4 Chiu Mok 01/01/1980 11 street
5 c m 01/01/1980 11 street 19/05/2011 10:00:00
6 ch Cooke 01/01/1981 23 dawnstreet
7 chris Cooke 01/01/1980 adaf 19/05/2011 16:00:00
8 Ni Me 01/11/1980 22 high street 19/05/2011 16:00:00

Result should be
Name
Nirav
Chiu
ch
SurName
Mok
Address
24 abc street
23 dawnstreet
 
Old May 19th, 2011, 11:05 AM
Friend of Wrox
 
Join Date: Sep 2010
Posts: 245
Thanks: 5
Thanked 24 Times in 23 Posts
Default

How do you determine what fields have changed?
__________________
Boyd Trimmell aka HiTechCoach (.com)
Microsoft Access MVP Alumni 2010-2015
 
Old May 19th, 2011, 11:16 AM
Registered User
 
Join Date: May 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

when datatimestamp is null means newly inserted field.
and 2nd consideration it should be unique.
 
Old May 19th, 2011, 12:40 PM
Friend of Wrox
 
Join Date: Sep 2010
Posts: 245
Thanks: 5
Thanked 24 Times in 23 Posts
Default

Quote:
Originally Posted by niravm View Post
when datatimestamp is null means newly inserted field.
and 2nd consideration it should be unique.
What should be unique?

I can't figure out your logic from looking ate your example of the tblMember table and the results. I don't see any pattern

What does the log file look like?

How do you know what has changed.

Unfortunately you are very vague. Please describe in detail exactly what you want. You will need to do this anyway you get a clear understanding of exactly what you need. Without a clear understanding of exactly what you need it will be very difficult to write the VBA code tht has to be specific on what exactly to do..

TIP: Programming is about specific instructions. If you can't write down exactly what you want to do with specific instructions (like if you were to do it manually) then you probably will not be able to program it either.
__________________
Boyd Trimmell aka HiTechCoach (.com)
Microsoft Access MVP Alumni 2010-2015
 
Old May 19th, 2011, 01:25 PM
Registered User
 
Join Date: May 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

there is nothing unique.
let tableMeber has 6 columns and only 3are text datatype
now in that table newly inserted record has null value in datetimestamp

so we have to filter records whose datetimestamp is null
now then from 3 text columns we have to find distinct value and store in logtable.

logtable has only one column which has values like

Name (field Name)
Nirav
Chiu
Chris
SurName (field Name)(only add if disctict value found in null datetime stamp record)

Address(same way)





Similar Threads
Thread Thread Starter Forum Replies Last Post
MS Access VBA Dateddiff Function SKZ Access VBA 5 November 18th, 2008 08:38 AM
VBA function help carbon_13 Excel VBA 2 March 5th, 2008 05:17 PM
Calling MS Access vba function via Excel Kourosha Excel VBA 0 December 31st, 2007 08:33 AM
Code works in Excel VBA but not Access VBA fossx Access VBA 2 May 21st, 2007 08:00 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.