Solved

Add Error Handling to code

Posted on 2013-05-13
2
390 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
2 Comments
 
LVL 46

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB6 - Convert HH:MM into Decimal 8 56
Add and format columns in vb6 7 57
Protecting vb6 & .Net code Obfuscation 18 124
clicking a shape in a frame array vb6 3 45
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

809 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