473,385 Members | 2,015 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.

need to create a log of actions performed by DAO/VBA

n8kindt
221 100+
hi, i have created a program that creates reports one by one and sends them out to the recepients systematically via email. i'm wondering how do i make a summary log report that reports what time a report was sent out, how many were sent out, how many failed, and any other actions performed within the code (with specific details about each one)... in other words, i need more than a count of how many were sent. then i need to export this data as a text file hopefully. where in the world do i start on this one? searching "vba report" gets me nowhere for fairly obvious reasons :)

i can post my code if need be, but i was just looking for someone to point me in the right direction so i can do it by myself.
Jun 2 '08 #1
15 1868
Zwoker
66
Hi,

It may be a little simplistic, but rather than trying to use any sort of MS Access report, you could just write the status of each activity that your program performs to a text file. You could use code something like the following:

Expand|Select|Wrap|Line Numbers
  1. Dim fs As Object
  2. Dim LogFile
  3.  
  4. Set fs = CreateObject("Scripting.FileSystemObject")
  5. Set LogFile = fs.CreateTextFile("ResultsLog.txt", True)
  6.  
  7. <if some table read action succeeded>
  8. LogFile.Writeline "Successfully read " & CustRst.RecordCount & " customer records"
  9. <or if something failed>
  10. LogFile.Writeline "Error is reading from Cust table"
  11.  
  12. LogFile.Close
Obviously this code is a little simple, and is a mixture of real code and pseudo-code, but I'm sure you get the idea.

And if anyone knows what type the LogFile should be declared as I'd appreciate you telling me. I couldn't work it out, but it works like this (in MS Access 2003, anyway).


Let me know if this is what you were looking for.


Regards,
Zwoker.
Jun 2 '08 #2
n8kindt
221 100+
Hi,

It may be a little simplistic, but rather than trying to use any sort of MS Access report, you could just write the status of each activity that your program performs to a text file. You could use code something like the following:

Expand|Select|Wrap|Line Numbers
  1. Dim fs As Object
  2. Dim LogFile
  3.  
  4. Set fs = CreateObject("Scripting.FileSystemObject")
  5. Set LogFile = fs.CreateTextFile("ResultsLog.txt", True)
  6.  
  7. <if some table read action succeeded>
  8. LogFile.Writeline "Successfully read " & CustRst.RecordCount & " customer records"
  9. <or if something failed>
  10. LogFile.Writeline "Error is reading from Cust table"
  11.  
  12. LogFile.Close
Obviously this code is a little simple, and is a mixture of real code and pseudo-code, but I'm sure you get the idea.

And if anyone knows what type the LogFile should be declared as I'd appreciate you telling me. I couldn't work it out, but it works like this (in MS Access 2003, anyway).


Let me know if this is what you were looking for.


Regards,
Zwoker.
perfect!! yes, that is exactly what i needed--nothing fancy. i appreciate your help! i'll see if i can get the LogFile declared properly...
Jun 2 '08 #3
Zwoker
66
perfect!! yes, that is exactly what i needed--nothing fancy. i appreciate your help! i'll see if i can get the LogFile declared properly...
The LogFile declaration will work as coded above, it just always bothered me that I couldn't discover what type it should actually be.

I'm glad this is what you were looking for. I wondered if you needed something a bit more sophisticated.


Regards,
Zwoker.
Jun 3 '08 #4
NeoPa
32,556 Expert Mod 16PB
A TextStream object might be what you're looking for (See http://www.csidata.com/custserv/onli...ocs/vbs279.htm)

I'm not sure which library this would be found in but I don't believe it's native Access.

An alternative approach (using very similar logic) would be to use Open# in VBA (look in Access Help for Open Statement).
Jun 3 '08 #5
n8kindt
221 100+
A TextStream object might be what you're looking for (See http://www.csidata.com/custserv/onli...ocs/vbs279.htm)

I'm not sure which library this would be found in but I don't believe it's native Access.

An alternative approach (using very similar logic) would be to use Open# in VBA (look in Access Help for Open Statement).
thanks for your post! i will look into that as well...

cheers
Jun 3 '08 #6
ADezii
8,834 Expert 8TB
You could use a low level I/O Function in conjunction with a Public Sub-Routine, to produce an impressive Log. A simple example would be:
Expand|Select|Wrap|Line Numbers
  1. Public Sub WriteToStatusFile(dteTimeOut As Date, intNumberSent As Integer, strStatus As String)
  2. Dim strMsg As String
  3.  
  4. strMsg = "Report Sent: " & Now() & vbCrLf
  5. strMsg = strMsg & "Number Sent: " & intNumberSent & vbCrLf
  6. strMsg = strMsg & "Status     : " & strStatus
  7.  
  8. Open "C:\Report Log.txt" For Append As #1
  9. Print #1, strMsg
  10. Print #1, "==========================================="
  11. Close #1
  12. End Sub
Sample Call to Routine
Expand|Select|Wrap|Line Numbers
  1. Call WriteToStatusFile(Now(), 122, "Success")
Sample Log File resulting from above Calls:
Expand|Select|Wrap|Line Numbers
  1. ===========================================
  2. Report Sent: 6/3/2008 10:25:43 PM
  3. Number Sent: 122
  4. Status     : Success
  5. ===========================================
  6. Report Sent: 6/3/2008 11:58:59 PM
  7. Number Sent: 0
  8. Status     : Failure
  9. ===========================================
Jun 4 '08 #7
FishVal
2,653 Expert 2GB
Would it be more suitable to store log in a table?
Text files are somewhat not suitable for further analyzing.

Regards,
Fish
Jun 4 '08 #8
ADezii
8,834 Expert 8TB
Would it be more suitable to store log in a table?
Text files are somewhat not suitable for further analyzing.

Regards,
Fish
Good point FishVal, and yes it would be more practical and efficient. I guess I just took the easy way out on this one, when I should have ran this option through the OP. Thanks again.
Jun 4 '08 #9
NeoPa
32,556 Expert Mod 16PB
It's a fair point Fish, but don't forget the code and ideas can be manipulated to do things different ways. Worth mentioning though.
Jun 4 '08 #10
n8kindt
221 100+
Would it be more suitable to store log in a table?
Text files are somewhat not suitable for further analyzing.

Regards,
Fish
i thought might be an option too... so should i just run an append query to fire off for each time something needs to be logged? i don't need anything too complex. but for history purposes i can see how the table idea is practical.
Jun 4 '08 #11
NeoPa
32,556 Expert Mod 16PB
The easiest way to convert ADezii's, already provided, code would be to use RecordSet processing code rather than SQL.

@ADezii
One simple comment I would make on the code provided, is that using FreeFile() to determine the file number (rather than simply using 1) would generally be recommended ;)
Jun 5 '08 #12
ADezii
8,834 Expert 8TB
The easiest way to convert ADezii's, already provided, code would be to use RecordSet processing code rather than SQL.

@ADezii
One simple comment I would make on the code provided, is that using FreeFile() to determine the file number (rather than simply using 1) would generally be recommended ;)
It is the generally accepted practice, and I always use it whenever I'm opening more than 1 File at a time, but you are correct in that it should always be used regardless of how many Files are being opened. Thanks for the pointer.
Jun 5 '08 #13
youmike
69
I would strongly recommend the use of a table to store log records. It gives the greatest flexibility in terms of layout to accommodate whatever action or event you might need to log and it can be interrogated by query and report, again in whatever format you need.

The systems that I design all have this need and I include a VB module into which parameters (such as userID, machineID, action, old value, new value, name of changed table, or whatever) are passed from wherever the need arises and written to tblLog. This log table always includes a field into which NOW is written.
Jun 6 '08 #14
n8kindt
221 100+
I would strongly recommend the use of a table to store log records. It gives the greatest flexibility in terms of layout to accommodate whatever action or event you might need to log and it can be interrogated by query and report, again in whatever format you need.

The systems that I design all have this need and I include a VB module into which parameters (such as userID, machineID, action, old value, new value, name of changed table, or whatever) are passed from wherever the need arises and written to tblLog. This log table always includes a field into which NOW is written.
this got me thinking... i have history events set up in 3 different tables. one for status changes, one for purchases, one for address changes, one for general profile history, and i will be creating one more for email receipt history. ok, i think that is more than 3 haha. anyways, i can set up a union query to combine all these records and sort them by time stamp right? or should i just redesign my database to chunk it all into one table?
Jun 8 '08 #15
NeoPa
32,556 Expert Mod 16PB
Hard to be absolute without a more in-depth understanding of your particular databse nate, but in general I would go for the single table approach.

UNION queries typically give poor performance due to the difficulty to optimise them (for Access at least).
Jun 9 '08 #16

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

Similar topics

1
by: Angela | last post by:
I wrote a class that I intended to be a custom action. I added the DLL for the class to the setup project using the CustomActions editor. When I run the installer it completely ignores the custom...
15
by: alanbe | last post by:
Greetings I am making a flashcard type application to help me in my TCP/IP protocols test. My instructor will test us periodically on how a device or networking function relates to the OSI...
48
by: Chad Z. Hower aka Kudzu | last post by:
A few of you may recognize me from the recent posts I have made about Indy <http://www.indyproject.org/indy.html> Those of you coming to .net from the Delphi world know truly how unique and...
6
by: SP | last post by:
Hi, I want to add wait cursor code whenever page is post back. Page may be post back on my user control's or on change of dropdown or on click of any button on page. so is there any common...
1
by: sandeepk84 | last post by:
hi all... does anyone know how v can commit d db actions performed using C#.. for eg. if i have created a table dynamically the database is 2 b refreshed to see it..can v commit by using d code???...
13
by: PinkBishop | last post by:
I am using VS 2005 with a formview control trying to insert a record to my access db. The data is submitted to the main table no problem, but I need to carry the catID to the bridge table...
1
by: pushrodengine via AccessMonster.com | last post by:
Is there a way to log user actions? What I would like is to be able to log user activities within the database. The table “tblUserEvents” would contain two fields. Field one “EventTime”...
1
by: javabeginner123 | last post by:
i have a java prob, and i have to solve it fast, but i'm just getting to know it, so plz help me solve it with full code completed, thanks so much. the prob is to create a monter fight and there is...
1
by: shapper | last post by:
Hello, I have a post controller with the following actions: Create / Insert, Destroy / Delete, Edit / Update. These take care of the CMS part. I have two other actions: - Show: displays a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.