Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 3rd, 2008, 05:37 PM
Authorized User
 
Join Date: Sep 2006
Location: Lenexa, KS, USA.
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
Reply With Quote
  #2 (permalink)  
Old March 4th, 2008, 09:14 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
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
Reply With Quote
  #3 (permalink)  
Old March 4th, 2008, 09:16 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
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
Reply With Quote
  #4 (permalink)  
Old March 4th, 2008, 02:46 PM
Authorized User
 
Join Date: Sep 2006
Location: Lenexa, KS, USA.
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...


Reply With Quote
  #5 (permalink)  
Old March 11th, 2008, 12:49 PM
Authorized User
 
Join Date: Sep 2006
Location: Lenexa, KS, USA.
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 & """"




Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 12:48 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.