By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,163 Members | 905 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,163 IT Pros & Developers. It's quick & easy.

Logfile

P: n/a
Hello,

is anyone willing to help me out to setup a logfile.
I have a program running in Access, but I want to know the progress of
it.
It is rather easy I think, but don't know how to handle it.
Basicly, I run macros and I just want to write a message to a file
before and after the run of that macro.
eg:

Write Date(), Time(),"Start" & "message 1" to logfile.txt
run macro1
Write Date(), Time(),"Stop" & "message 1" to logfile.txt
Write Date(), Time(),"Start" & "message 2" to logfile.txt
run macro2
Write Date(), Time(),"Stop" & "message 2" to logfile.txt
Write Date(), Time(),"Start" & "message 3" to logfile.txt
run macro3
Write Date(), Time(),"Stop" & "message 3" to logfile.txt
Who can help me out? Tnx.

Oct 5 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
ro***************@gmail.com wrote:
Hello,

is anyone willing to help me out to setup a logfile.
I have a program running in Access, but I want to know the progress of
it.
It is rather easy I think, but don't know how to handle it.
Basicly, I run macros and I just want to write a message to a file
before and after the run of that macro.
eg:

Write Date(), Time(),"Start" & "message 1" to logfile.txt
run macro1
Write Date(), Time(),"Stop" & "message 1" to logfile.txt
Write Date(), Time(),"Start" & "message 2" to logfile.txt
run macro2
Write Date(), Time(),"Stop" & "message 2" to logfile.txt
Write Date(), Time(),"Start" & "message 3" to logfile.txt
run macro3
Write Date(), Time(),"Stop" & "message 3" to logfile.txt
Who can help me out? Tnx.
Some code straight out of help.

Open "TESTFILE" For Output As #1 ' Open file for output.
Print #1, "This is a test" ' Print text to file.
Print #1, ' Print blank line to file.
Print #1, "Zone 1"; Tab ; "Zone 2" ' Print in two print zones.
Print #1, "Hello" ; " " ; "World" ' Separate strings with space.
Print #1, Spc(5) ; "5 leading spaces " ' Print five leading spaces.
Print #1, Tab(10) ; "Hello" ' Print word at column 10.

' Assign Boolean, Date, Null and Error values.
Dim MyBool, MyDate, MyNull, MyError
MyBool = False : MyDate = #February 12, 1969# : MyNull = Null
MyError = CVErr(32767)
' True, False, Null, and Error are translated using locale settings of
' your system. Date literals are written using standard short date
' format.
Print #1, MyBool ; " is a Boolean value"
Print #1, MyDate ; " is a date"
Print #1, MyNull ; " is a null value"

Print #1, MyError ; " is an error value"
Close #1 ' Close file.
Oct 5 '06 #2

P: n/a

maybe I didn't expressed well what I had in mind.
The issue is that I just want to find a way to fill up the log file
with messages generated as the process flows.
Every time I think it is necessary (predefined positions), I would like
to write to the log file by activating a procedure that just needs the
name of the process and some text as parameter; something like: Run
logging, "Message 1".
In the procedure the message is written to the logfile and added with a
Date and Time.

Can this be done easily?

Oct 5 '06 #3

P: n/a
ro***************@gmail.com wrote:
maybe I didn't expressed well what I had in mind.
The issue is that I just want to find a way to fill up the log file
with messages generated as the process flows.
Every time I think it is necessary (predefined positions), I would like
to write to the log file by activating a procedure that just needs the
name of the process and some text as parameter; something like: Run
logging, "Message 1".
In the procedure the message is written to the logfile and added with a
Date and Time.

Can this be done easily?
You asked how to send some text to write to a log file.

I provided an example. I recommend you run it. See the results.

It can be done easily.

You did not understand the code provided.

The question is...can you program?

Also, look at RunCode in help.

Oct 5 '06 #4

P: n/a
Dear Salad,

indeed, I'm not a programmer at all. I used to write programs in Dbase.
There I had the possibillity to run a program with extra parameters.
Via this program, and parameters, similar to what your wrote out for
me, the result came as easy as you tell it so well.
The problem is, How can I activate the code in the module and where do
I write my parameter.

By the way, find some code I used in a form where the procedure runs on
the on load event.
This is working well but the question remain. How can I fill my
variable "logentry" from outside??

Option Compare Database
Dim StrPath As String

Private Sub Form_Load()
Dim fn As Integer
fn = FreeFile
StrPath = "I:\be\_agb\Agfaproj\Logistiek\WOS"
logentry = "Testing to write to the logfile"
Open StrPath & "\WOS_Logging.txt" For Append As #fn
Write #fn, Now & ": " & logentry
Close #fn

End Sub
salad schreef:
salad schreef:
ro***************@gmail.com wrote:
maybe I didn't expressed well what I had in mind.
The issue is that I just want to find a way to fill up the log file
with messages generated as the process flows.
Every time I think it is necessary (predefined positions), I would like
to write to the log file by activating a procedure that just needs the
name of the process and some text as parameter; something like: Run
logging, "Message 1".
In the procedure the message is written to the logfile and added with a
Date and Time.

Can this be done easily?
You asked how to send some text to write to a log file.

I provided an example. I recommend you run it. See the results.

It can be done easily.

You did not understand the code provided.

The question is...can you program?

Also, look at RunCode in help.
Oct 5 '06 #5

P: n/a
ro***************@gmail.com wrote:
Dear Salad,

indeed, I'm not a programmer at all. I used to write programs in Dbase.
There I had the possibillity to run a program with extra parameters.
Via this program, and parameters, similar to what your wrote out for
me, the result came as easy as you tell it so well.
The problem is, How can I activate the code in the module and where do
I write my parameter.
See code below. Hmmm...oftentimes you exectute an action by pressing on
a command button...or some other event that you want to start the process.

If you are using a macro, and a command button, in the OnClick event
enter the name of the Macro. Or use VBA.

DoCmd.RunMacro "Macro1"

>
By the way, find some code I used in a form where the procedure runs on
the on load event.
This is working well but the question remain. How can I fill my
variable "logentry" from outside??
Oftentimes you declare a field on a form (you can make invisible if you
don't want it seen). Then
Write #fn, Now & ": " & Me.logentry

Or maybe you declared the variable as public under the Option Explicit
line at the top of the code module.

Option Compare Database
Option Explicit
Dim logentry as String

What/when you assign to logentry is up to you.

Option Compare Database
Dim StrPath As String

Private Sub Form_Load()
Dim fn As Integer
fn = FreeFile
StrPath = "I:\be\_agb\Agfaproj\Logistiek\WOS"
logentry = "Testing to write to the logfile"
Open StrPath & "\WOS_Logging.txt" For Append As #fn
Write #fn, Now & ": " & logentry
Close #fn

End Sub
What I might do is:
Open up a code module. Make a public sub that gets a message. Ex:
Public Sub WriteLog(strMsg As String, blnBlank As Boolean)
Open "LogFile" For Output As #1 ' Open file for output.
'print the message
Print #1, Date(); Tab ; Time() ; Tab ; _
IIF(Not blnBlank,"Start ","End ") & strMsg
'if this is the stop line, print a blank line
If blnBlank then Print #1,
Close #1 ' Close file.
End Sub

I am assuming you are using macros.
Now, in your macro, you call this code with RunCode. Or use VBA from
above to call WriteLog and then the macro
'Write Date(), Time(),"Start" & "message 1" to logfile.txt
Runcode WriteLog("Message 1",False)

run macro1

'Write Date(), Time(),"Stop" & "message 1" to logfile.txt
Runcode WriteLog("Message 1",True)

'Write Date(), Time(),"Start" & "message 2" to logfile.txt
Runcode WriteLog("Message 2",False)
etc

Not sure what message you pass to the routine via RunCode. You might be
better off just writing the whole thing in VBA. Like
Private Sub Command1_Click()
'uses routing blow this code block
WriteLog "Message variable", False
Docmd.RunMacro "Macro1"
WriteLog "Message variable", True
....
End Sub


>

salad schreef:
salad schreef:

>>ro***************@gmail.com wrote:

>>>maybe I didn't expressed well what I had in mind.
The issue is that I just want to find a way to fill up the log file
with messages generated as the process flows.
Every time I think it is necessary (predefined positions), I would like
to write to the log file by activating a procedure that just needs the
name of the process and some text as parameter; something like: Run
logging, "Message 1".
In the procedure the message is written to the logfile and added with a
Date and Time.

Can this be done easily?

You asked how to send some text to write to a log file.

I provided an example. I recommend you run it. See the results.

It can be done easily.

You did not understand the code provided.

The question is...can you program?

Also, look at RunCode in help.

Oct 5 '06 #6

P: n/a
Dear Salad,

now you are writing real stuff; thank you very much.
The last part, to write the hole thing in VBA seems to me the most
apropriate.

Again, thank you for the advise and the attention to my problem.

Good luck, Roger
What I might do is:
Open up a code module. Make a public sub that gets a message. Ex:
Public Sub WriteLog(strMsg As String, blnBlank As Boolean)
Open "LogFile" For Output As #1 ' Open file for output.
'print the message
Print #1, Date(); Tab ; Time() ; Tab ; _
IIF(Not blnBlank,"Start ","End ") & strMsg
'if this is the stop line, print a blank line
If blnBlank then Print #1,
Close #1 ' Close file.
End Sub

I am assuming you are using macros.
Now, in your macro, you call this code with RunCode. Or use VBA from
above to call WriteLog and then the macro
'Write Date(), Time(),"Start" & "message 1" to logfile.txt
Runcode WriteLog("Message 1",False)

run macro1

'Write Date(), Time(),"Stop" & "message 1" to logfile.txt
Runcode WriteLog("Message 1",True)

'Write Date(), Time(),"Start" & "message 2" to logfile.txt
Runcode WriteLog("Message 2",False)
etc

Not sure what message you pass to the routine via RunCode. You might be
better off just writing the whole thing in VBA. Like
Private Sub Command1_Click()
'uses routing blow this code block
WriteLog "Message variable", False
Docmd.RunMacro "Macro1"
WriteLog "Message variable", True
....
End Sub
Oct 6 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.