I have code that loops through a directory and outputs files to a .htm page based on a search criteria that the user enters. I would like to have one heading on the page but everytime it loops through the directory it adds another header. I'm trying to determine a way for the code to detect if the header exists and if it does to stop adding the headers. Any guidance you can provide would be greatly appreciated.
Sub CheckFolder(objCurrentFolder,objLogFile,State,Yr,Evt)
Dim strSearch
Dim strStYr
Dim strYr
Dim strShip
Dim strEvent
Dim strOutput
Dim strOutput1
Dim objNewFolder
Dim objFile
Dim objStream
Dim objShell
Dim Getyr
Dim GetShip
Dim GetEvent
Dim EvtName
Dim intCount
'Dim intCount2
Dim HeaderExists
GetState = State
GetYr = Yr
GetEvent = Evt
GetShip = Ship
If evt = "N" Then
EvtName = "Natality"
ElseIf evt = "M" Then
EvtName = "Mortality"
ElseIf evt = "F" Then
EvtName = "Fetal Death"
ElseIf evt = "T" Then
EvtName = "Medical"
End If
strOutput1 = "<h3><center>Search Results for" & Chr(32) & GetState & Chr(32) & GetYr & Chr(32) & "*" & _
Chr(32) & EvtName & "</center></h3>"
objLogFile.writeline strOutput1
For Each objFile In objCurrentFolder.Files
strStYr=Mid(objFile.Name,6,4)
strEvent = Mid(objFile.Name,13,1)
strSearch = strStYr & strEvent
If strSearch=GetState & GetYr & GetEvent Then
intCount = intCount + 1
'Alternating Row Colors
If intCount Mod 2 = 0 Then
strOutput = "<table>" & "<tr bgcolor=#CAE1FF>" & "<td>" & "TSA:" & _
Chr(32) & Chr(32) & "<A href=" & _
CStr(objFile.Path) & ">" & CStr(objFile.Path) & "</A>" & Chr(32) & _
"CREATED:" & Chr(32) & CStr(objFile.datecreated) & "</td>" & "</tr>" & "</table>" & Chr(13)
objLogFile.writeline strOutput
Else
strOutput = "<table>" & "<tr bgcolor=#C1FFB1>" & "<td>" & "TSA:" & _
Chr(32) & Chr(32) & "<A href=" & _
CStr(objFile.Path) & ">" & CStr(objFile.Path) & "</A>" & Chr(32) & _
"CREATED:" & Chr(32) & CStr(objFile.datecreated) & "</td>" & "</tr>" & "</table>" & Chr(13)
objLogFile.writeline strOutput
End If
End If
Next
'Recurse Through all of the folders
For each objNewFolder In objCurrentFolder.subFolders
CheckFolder objNewFolder, objLogFile, State, Yr, Evt
Next
End Sub
Sub CheckFolder(objCurrentFolder,objLogFile,State,Yr,Evt)
Dim strSearch
Dim strStYr
Dim strYr
Dim strShip
Dim strEvent
Dim strOutput
Dim strOutput1
Dim objNewFolder
Dim objFile
Dim objStream
Dim objShell
Dim Getyr
Dim GetShip
Dim GetEvent
Dim EvtName
Dim intCount
'Dim intCount2
Dim HeaderExists
GetState = State
GetYr = Yr
GetEvent = Evt
GetShip = Ship
If evt = "N" Then
EvtName = "Natality"
ElseIf evt = "M" Then
EvtName = "Mortality"
ElseIf evt = "F" Then
EvtName = "Fetal Death"
ElseIf evt = "T" Then
EvtName = "Medical"
End If
strOutput1 = "<h3><center>Search Results for" & Chr(32) & GetState & Chr(32) & GetYr & Chr(32) & "*" & _
Chr(32) & EvtName & "</center></h3>"
objLogFile.writeline strOutput1
For Each objFile In objCurrentFolder.Files
strStYr=Mid(objFile.Name,6,4)
strEvent = Mid(objFile.Name,13,1)
strSearch = strStYr & strEvent
If strSearch=GetState & GetYr & GetEvent Then
intCount = intCount + 1
'Alternating Row Colors
If intCount Mod 2 = 0 Then
strOutput = "<table>" & "<tr bgcolor=#CAE1FF>" & "<td>" & "TSA:" & _
Chr(32) & Chr(32) & "<A href=" & _
CStr(objFile.Path) & ">" & CStr(objFile.Path) & "</A>" & Chr(32) & _
"CREATED:" & Chr(32) & CStr(objFile.datecreated) & "</td>" & "</tr>" & "</table>" & Chr(13)
objLogFile.writeline strOutput
Else
strOutput = "<table>" & "<tr bgcolor=#C1FFB1>" & "<td>" & "TSA:" & _
Chr(32) & Chr(32) & "<A href=" & _
CStr(objFile.Path) & ">" & CStr(objFile.Path) & "</A>" & Chr(32) & _
"CREATED:" & Chr(32) & CStr(objFile.datecreated) & "</td>" & "</tr>" & "</table>" & Chr(13)
objLogFile.writeline strOutput
End If
End If
Next
'Recurse Through all of the folders
For each objNewFolder In objCurrentFolder.subFolders
CheckFolder objNewFolder, objLogFile, State, Yr, Evt
Next
End Sub