Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
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 March 3rd, 2008, 05:37 PM
Authorized User
 
Join Date: Sep 2006
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to log to server's event log

Hi all,

I'm writing a VBA Access 2003 app which will have to log an event to the event log of the server it runs on, so that it'll be visible from the Event Viewer. I just can't find any examples of this; can anybody tell me how, or point me towards an example? Many thanks in advance... - LenexaKS
 
Old March 4th, 2008, 09:14 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

I don't think you can get access to the Server's Event log system other than the Application Log. You can write to the Application log using WSH like this:

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.LogEvent 0, "My application succeeded.", "\\YourServerName"

If the script is being run on "YourServerName" in this case, then that line would omit the UNC reference to the server, like this:

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.LogEvent 0, "My application succeeded."

The number codes are:

0 = Success
1 = Failure
2 = Warning
4 = Information

The event will be recorded and having come from "Windows Script Host" so when you read the log, you need to look for this source.

Did that help?

mmcdonal

Look it up at: http://wrox.books24x7.com
 
Old March 4th, 2008, 09:16 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

I forgot to mention, if you have to declare WshShell, use either variant or nothing (variant) like this:

Dim WshShell As Variant

or

Dim WshShell

HTH

mmcdonal

Look it up at: http://wrox.books24x7.com
 
Old March 4th, 2008, 02:46 PM
Authorized User
 
Join Date: Sep 2006
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi mmcdonal,

I did...
  Declare WshShell As Variant
  Set WshShell = Wscript.CreateObject("WScript.Shell")
but it immediately threw error 424, Object Required.

It threw the same error when I tried the real basic step of:
  Wscript.Echo "The version of WSH on this computer is: " & WScript.Version

I briefly saw, then lost track of , a webpage which mentions the Windows Scripting Host process. Nothing named anything like this is running as a process on the machine I’m developing on… should it be?

Also, I had the above code in my VBA/Access app - was that what you had in mind?
I found a website that said that code just like your example should be in a VBScript. In the past and in the examples I’ve just found, I’ve only seen VBScript embedded in HTML, like JavaScript is, but of course an Access app has no HTML. How would one go about this?

I appreciate your help! Thanks...


 
Old March 11th, 2008, 12:49 PM
Authorized User
 
Join Date: Sep 2006
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Details/Summary for future searchers:

Mmcdonal's (thanks again) suggested VBScript code goes in a scriptname.vbs file:
  Dim WshShell
  Set WshShell = WScript.CreateObject("WScript.Shell")
  WshShell.LogEvent 0, WScript.Arguments(0)

In the VBA code, do:
  Shell "Wscript.exe C:\[path]\scriptname.vbs " & YourEventText

YourEventText will probably be multiple words, so group the whole event message string in double quotes first, or it'll treat it as multiple incoming arguments:
  MessageText = """" & MessageText & """"









Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't get Log to write the Log.txt file jnbutler BOOK: Professional XNA Game Programming: For Xbox 360 and Windows ISBN: 978-0-470-12677-6 3 July 31st, 2007 04:04 AM
Event Log dkspivey ASP.NET 1.0 and 1.1 Basics 3 August 22nd, 2005 11:19 AM
AppException Class -Log Error to Event Log bekim BOOK: ASP.NET Website Programming Problem-Design-Solution 7 December 7th, 2004 01:01 PM
Security exception comes when writing to event log s_vermani BOOK: Beginning ASP.NET 1.0 4 October 21st, 2004 09:17 AM
Event log to a text file jackchua BOOK: ASP.NET Website Programming Problem-Design-Solution 2 May 17th, 2004 09:54 PM





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