Solved

Add Error Handling to code

Posted on 2013-05-13
2
394 Views
Last Modified: 2013-05-15
I have the following code.  It runs fine unless one of the PCs in the Array is not available.  Then it stops and all of the PCs after the failed one log no data.  

How can I manage the error so it continues throught the whole array?


Set objFSO = CreateObject("Scripting.FileSystemObject")
Const ForAppending = 2
Dim objFSO:Set objFSO = CreateObject("Scripting.FileSystemObject")

Dim myDateString0, myDateString1, myDateString2, break
myDateString = FormatDateTime(Date(), 0)
fileDate = Replace(myDateString, "/", "-") & "-" & Replace(Time, ":", "-")

Dim RunStamp
RunStamp = FormatDateTime(Now(),0)

'set up log file - edit this to change path and name
'LogFile = "\\eis62pc\SummitHealthcare\DRS Desktop 3\Reports\" & "audit-" & fileDate & ".txt"
LogFile = "C:\Summit\" & "audit-" & fileDate & ".txt"
Dim objLogFile:Set objLogFile = objFSO.CreateTextFile(logfile, 2, True)

'create an array of workstations - add more to the end of this list if you want
Set workstationList = CreateObject( "System.Collections.ArrayList" )
workstationList.Add "2MNA24PC"
workstationList.Add "3MSB11PC"
workstationList.Add "4MSB23PC"
workstationList.Add "5MNA11PC"
workstationList.Add "E2E05PC"
workstationList.Add "E3W08PC"
workstationList.Add "ECPOE15PC"
workstationList.Add "EIS42PC"
workstationList.Add "EIS62PC"
workstationList.Add "EIS58PC"
workstationList.Add "ENA05PC"
workstationList.Add "EIS38PC"

'workstationList.Add "D"
'workstationList.Add "C"


'Print banner
'objLogFile.Write "Offline Report Audit"
'objLogFile.Writeline "Listing for: " & objFolder.Path
'objLogFile.Writeline "Run Date: " & myDateString & " " & Time
'objLogFile.Writeline

'loop through all of the files
For Each strItem in workstationList
      'path to files to list
      objStartFolder = "\\" & strItem & "\SummitHealthcare\DRS Desktop 3\Reports"
      Set objFolder = objFSO.GetFolder(objStartFolder)
      Set colFiles = objFolder.Files
      ShowSubfolders objFSO.GetFolder(objStartFolder)
Next


Sub ShowSubFolders(Folder)
        For Each objFile in colFiles
            'objLogFile.Write chr(34) & strItem & chr(34) & "," & chr(34) & objFile.Name & chr(34) & "," & chr(34) & objFile.DateLastModified & chr(34)
                  objLogFile.Write chr(34) & strItem & chr(34) & "," & chr(34) & objFile.Name & chr(34) & "," & chr(34) & objFile.DateLastModified & chr(34) & "," & chr(34) & RunStamp & chr(34) 'FormatDateTime(Now(),0)  
            objLogFile.Writeline
        Next
   
End Sub

objLogFile.Close
0
Comment
Question by:Scotto111
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 47

Assisted Solution

by:Martin Liss
Martin Liss earned 225 total points
ID: 39162830
Try adding On Error Resume Next near the top.
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 225 total points
ID: 39163306
Or you could change these lines
      Set objFolder = objFSO.GetFolder(objStartFolder)
      Set colFiles = objFolder.Files
      ShowSubfolders objFSO.GetFolder(objStartFolder)

Open in new window


to this
      If objFSO.FolderExists(objStartFolder) = True Then
	      Set objFolder = objFSO.GetFolder(objStartFolder)
	      Set colFiles = objFolder.Files
	      ShowSubfolders objFSO.GetFolder(objStartFolder)
      End If

Open in new window


so that you confirm whether the folder is accessible first.

Regards,

Rob.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question