Hi ,
I have being requested to create a from that displays the number of files in different folders. I can accomplish this somewhat with the code below. In the example below it is only showing the code for the first 3 folders. I have 7 folders in total to count.
I have 2 problems that I hope you can help me with?
1. Each week the location of the data will change. In the example below it is showing 2014-W03, the following week it will be 2014-W04 etc. etc. I was thinking of having an input box in the form that the user type the date into, to trigger the code, but how would I go about changing the code to include this variable?
2. I need to repeat this code for 9 other products, so my form will be displaying data for 10 products in total. I know I could copy this code 9 times and modify it accordingly, but is it possible to loop it in some way?
Thank in advance,
Poco
I have being requested to create a from that displays the number of files in different folders. I can accomplish this somewhat with the code below. In the example below it is only showing the code for the first 3 folders. I have 7 folders in total to count.
I have 2 problems that I hope you can help me with?
1. Each week the location of the data will change. In the example below it is showing 2014-W03, the following week it will be 2014-W04 etc. etc. I was thinking of having an input box in the form that the user type the date into, to trigger the code, but how would I go about changing the code to include this variable?
2. I need to repeat this code for 9 other products, so my form will be displaying data for 10 products in total. I know I could copy this code 9 times and modify it accordingly, but is it possible to loop it in some way?
Thank in advance,
Poco
Code:
' Returns the total number of fails
Private Sub Form_Load()
Dim file As Object
Dim fileCount As Long
With CreateObject("Scripting.FileSystemObject").getfolder("\\testmachine\Product1\ FAILS\2014-W03")
For Each file In .Files
If file.Name Like "*.*" Then
fileCount = fileCount + 1
End If
Next file
End With
Me.FailTotal = fileCount
' Returns the total number of passes
Dim file2 As Object
Dim fileCount2 As Long
With CreateObject("Scripting.FileSystemObject").getfolder("\\testmachine\Product1\ PASS\2014-W03")
For Each file2 In .Files
If file2.Name Like "*.*" Then
fileCount2 = fileCount2 + 1
End If
Next file2
End With
Me.Total = fileCount2
' Returns the total number of fail1 fails
Dim filef1 As Object
Dim fileCountf1 As Long
With CreateObject("Scripting.FileSystemObject").getfolder("\\testmachine\Product1\ FAILS\2014-W03")
For Each filef1 In .Files
If filef1.Name Like "*FAIL1*" Then
fileCountf1 = fileCountf1 + 1
End If
Next filef1
End With
Me.Energise = fileCountf1