| Line-No. / Ref. | Code Line |
| 0001 | Public Sub Spider_Archived_Notes_Import() |
| 0002 | Dim DirectoryName As String |
| 0003 | Dim strTitle As String |
| 0004 | Dim strNote_Text As String |
| 0005 | Dim strArchived_Timestamp As String |
| 0006 | Dim File_Wanted As String |
| 0007 | Dim File_Name As String |
| 0008 | Dim File_Name_Full As String |
| 0009 | Dim File_Name_Full_Out As String |
| 0010 | Dim File_Extension As String |
| 0011 | Dim strLine As String |
| 0012 | Dim strLineMore As String |
| 0013 | Dim LenstrLine As Long |
| 0014 | Dim LenstrLineMore As Long |
| 0015 | Dim File_Timestamp As Date |
| 0016 | Dim InFile As String |
| 0017 | Dim i As Long |
| 0018 | Dim j As Long |
| 0019 | Dim k As Long |
| 0020 | Dim m As Long |
| 0021 | Dim fso As FileSystemObject |
| 0022 | Dim tsTextFileIn As TextStream |
| 0023 | Dim MainFolder |
| 0024 | Dim FileCollection |
| 0025 | Dim File |
| 0026 | Dim fsoTextFile As FileSystemObject |
| 0027 | Dim rsFile_List As Recordset |
| 0028 | Dim rsNotes As Recordset |
| 0029 | Dim rsNotes_Archive As Recordset |
| 0030 | Dim rsNotes_Archive_Temp As Recordset |
| 0031 | Dim strQuery As String |
| 0032 | Dim strNotesID As String |
| 0033 | strQuery = "SELECT Backup_Site_Map.Directory, Backup_Site_Map.FIle_Name, Backup_Site_Map.Full_File_Name, Backup_Site_Map.File_Timestamp FROM Backup_Site_Map WHERE (((Backup_Site_Map.Directory) Like """ & TheoWebsiteRoot & "\Notes\Notes_*"" And (Backup_Site_Map.Directory) Not Like ""*Notes_Print*"" AND (Backup_Site_Map.FIle_Name) Like ""Notes_268_*""));" |
| 0034 | Set rsFile_List = CurrentDb.OpenRecordset(strQuery) |
| 0035 | If Not rsFile_List.EOF Then |
| 0036 | rsFile_List.MoveFirst |
| 0037 | End If |
| 0038 | DirectoryName = "C:\Theo's Files\Birkbeck\Spider_Test\" |
| 0039 | Set fso = CreateObject("Scripting.FileSystemObject") |
| 0040 | DoCmd.OpenQuery ("Notes_Archive_Temp_Zap") |
| 0041 | Do While Not rsFile_List.EOF |
| 0042 | File_Name_Full = rsFile_List.Fields(1) |
| 0043 | File_Timestamp = rsFile_List.Fields(3) |
| 0044 | i = InStr(1, File_Name_Full, ".") |
| 0045 | If i = 0 Then |
| 0046 | File_Wanted = "No" |
| 0047 | Else |
| 0048 | File_Name = Left(File_Name_Full, i - 1) |
| 0049 | File_Extension = UCase(Mid(File_Name_Full, 1 + i, 20)) |
| 0050 | If File_Extension = "HTM" Or File_Extension = "HTML" Then |
| 0051 | File_Wanted = "Yes" |
| 0052 | Else |
| 0053 | File_Wanted = "No" |
| 0054 | End If |
| 0055 | End If |
| 0056 | If File_Wanted = "Yes" Then |
| 0057 | 'Check it's an archived Notes file |
| 0058 | If Left(File_Name, 6) = "Notes_" Then |
| 0059 | i = InStr(File_Name, "_") |
| 0060 | j = InStr(i + 1, File_Name, "_") |
| 0061 | If j > 0 Then |
| 0062 | strArchived_Timestamp = Mid(File_Name, j + 1, 100) |
| 0063 | strNotesID = Mid(File_Name, i + 1, j - i - 1) |
| 0064 | Debug.Print Now() & " - "; strNotesID |
| 0065 | Debug.Print Now() & " - "; strArchived_Timestamp |
| 0066 | Else |
| 0067 | File_Wanted = "No" |
| 0068 | End If |
| 0069 | Else |
| 0070 | File_Wanted = "No" |
| 0071 | End If |
| 0072 | End If |
| 0073 | 'Check if it's already in the archived database ... |
| 0074 | If File_Wanted = "Yes" Then |
| 0075 | strQuery = "SELECT Archived_Notes_Files.ID, Archived_Notes_Files.Item_Title, Archived_Notes_Files.Item_Text, Archived_Notes_Files.[Jump_Table?], Archived_Notes_Files.Note_Group, Archived_Notes_Files.Master_Note, Archived_Notes_Files.Last_Changed, Archived_Notes_Files.[Private?], Archived_Notes_Files.Status, Archived_Notes_Files.[Title?], Archived_Notes_Files.[Respondent?], Archived_Notes_Files.Timestamp, Archived_Notes_Files.Frozen_Timestamp, Archived_Notes_Files.Archived_File FROM Archived_Notes_Files WHERE (((Archived_Notes_Files.Archived_File)=""" & File_Name_Full & """));" |
| 0076 | Set rsNotes_Archive = CurrentDb.OpenRecordset(strQuery) |
| 0077 | If Not rsNotes_Archive.EOF Then |
| 0078 | File_Wanted = "No" |
| 0079 | Debug.Print Now() & " - "; "Already in Database" |
| 0080 | End If |
| 0081 | End If |
| 0082 | If File_Wanted = "Yes" Then |
| 0083 | InFile = rsFile_List.Fields(2) |
| 0084 | Set tsTextFileIn = fso.OpenTextFile(InFile, ForReading, True, 0) 'Open the file |
| 0085 | Set fsoTextFile = New FileSystemObject |
| 0086 | File_Name_Full_Out = DirectoryName & File_Name & ".txt" |
| 0087 | Set tsTextFile = fsoTextFile.CreateTextFile(File_Name_Full_Out, True, True) |
| 0088 | strLine = tsTextFileIn.ReadLine |
| 0089 | j = 1 |
| 0090 | Do Until tsTextFileIn.AtEndOfStream |
| 0091 | LenstrLine = Len(strLine) |
| 0092 | strLineMore = tsTextFileIn.ReadLine |
| 0093 | j = j + 1 |
| 0094 | If j = 4 Then |
| 0095 | k = InStr(strLineMore, "respondent") |
| 0096 | 'Find the title ... need to watch out if there's no title, and special case for respondents! |
| 0097 | strTitle = "" |
| 0098 | If k > 0 Then |
| 0099 | Debug.Print Now() & " - "; strLineMore |
| 0100 | k = InStr(strLineMore, "
") |
| 0101 | If k > 0 Then |
| 0102 | k = InStr(k + Len("
"), strLineMore, ">") |
| 0103 | If k > 0 Then |
| 0104 | strLineMore = Mid(strLineMore, k + 1, Len(strLineMore)) |
| 0105 | strLineMore = Replace(strLineMore, "", "") |
| 0106 | strLineMore = Replace(strLineMore, "", "") |
| 0107 | strLineMore = Replace(strLineMore, "", "") |
| 0108 | strLineMore = Replace(strLineMore, "", "") |
| 0109 | strLineMore = Replace(strLineMore, "", "") |
| 0110 | strLineMore = Replace(strLineMore, "", "") |
| 0111 | strLineMore = Replace(strLineMore, "", "") |
| 0112 | k = InStr(strLineMore, "<") |
| 0113 | If k > 0 Then |
| 0114 | strTitle = Left(strLineMore, k - 1) |
| 0115 | End If |
| 0116 | End If |
| 0117 | End If |
| 0118 | Else |
| 0119 | strLineMore = Replace(strLineMore, "", "") |
| 0120 | strLineMore = Replace(strLineMore, "", "") |
| 0121 | strLineMore = Replace(strLineMore, "", "") |
| 0122 | strLineMore = Replace(strLineMore, "", "") |
| 0123 | strLineMore = Replace(strLineMore, "", "") |
| 0124 | strLineMore = Replace(strLineMore, "", "") |
| 0125 | i = 1 |
| 0126 | Do Until i = 0 |
| 0127 | m = i |
| 0128 | i = InStr(i + 1, strLineMore, """>") |
| 0129 | Loop |
| 0130 | k = InStr(m, strLineMore, "<") |
| 0131 | If m > 1 Then |
| 0132 | If k > 0 Then |
| 0133 | strTitle = Mid(strLineMore, m + 2, k - m - 2) |
| 0134 | Else |
| 0135 | strTitle = Mid(strLineMore, m + 2, Len(strLineMore)) |
| 0136 | End If |
| 0137 | Else |
| 0138 | If k > 0 Then |
| 0139 | strTitle = Left(strLineMore, k - 1) |
| 0140 | Else |
| 0141 | strTitle = Left(strLineMore, Len(strLineMore)) |
| 0142 | End If |
| 0143 | End If |
| 0144 | If Len(Trim(strTitle)) = 0 Then |
| 0145 | Debug.Print Now() & " - "; strLineMore |
| 0146 | Else |
| 0147 | Debug.Print Now() & " - "; strTitle |
| 0148 | End If |
| 0149 | End If |
| 0150 | End If |
| 0151 | If j = 5 Then |
| 0152 | 'Main Text |
| 0153 | strNote_Text = strLineMore |
| 0154 | tsTextFile.WriteLine strNote_Text |
| 0155 | End If |
| 0156 | LenstrLineMore = Len(strLineMore) |
| 0157 | strLine = strLine & strLineMore |
| 0158 | If (LenstrLine + LenstrLineMore <> Len(strLine)) Then |
| 0159 | 'Probably superfluous check for text overflow |
| 0160 | MsgBox (LenstrLine) |
| 0161 | End If |
| 0162 | Loop |
| 0163 | Set tsTextFile = Nothing |
| 0164 | 'Now carry out inverse transformations |
| 0165 | OK = Spider_Note_Remove_Section(strNote_Text) |
| 0166 | OK = Spider_Note_Remove_Hyperlinks(strNote_Text) |
| 0167 | OK = Spider_Note_Reverse_Bullets(strNote_Text) |
| 0168 | OK = Spider_Note_Remove_Paragraph(strNote_Text) |
| 0169 | OK = Spider_Note_Remove_Printable_Versions(strNote_Text) |
| 0170 | 'Now write out the file |
| 0171 | Set fsoTextFile = New FileSystemObject |
| 0172 | File_Name_Full_Out = DirectoryName & File_Name & ".txt" |
| 0173 | Set tsTextFile = fsoTextFile.CreateTextFile(File_Name_Full_Out, True, True) |
| 0174 | tsTextFile.WriteLine strNote_Text |
| 0175 | Set tsTextFile = Nothing |
| 0176 | 'Obtain information from Note |
| 0177 | strQuery = "SELECT Notes.* FROM Notes WHERE (((Notes.ID)=" & Val(strNotesID) & "));" |
| 0178 | Set rsNotes = CurrentDb.OpenRecordset(strQuery) |
| 0179 | If rsNotes.EOF Then |
| 0180 | Debug.Print Now() & " - "; "Note " & strNotesID & " does not exist" |
| 0181 | Else |
| 0182 | rsNotes.MoveFirst |
| 0183 | 'Update Notes_Archive_Temp |
| 0184 | strQuery = "SELECT Notes_Archive_Temp.ID, Notes_Archive_Temp.Item_Title, Notes_Archive_Temp.Item_Text, Notes_Archive_Temp.[Jump_Table?], Notes_Archive_Temp.Note_Group, Notes_Archive_Temp.Master_Note, Notes_Archive_Temp.Last_Changed, Notes_Archive_Temp.[Private?], Notes_Archive_Temp.Status, Notes_Archive_Temp.[Title?], Notes_Archive_Temp.[Respondent?], Notes_Archive_Temp.Timestamp, Notes_Archive_Temp.Frozen_Timestamp FROM Notes_Archive_Temp WHERE (((Notes_Archive_Temp.ID)=" & Val(strNotesID) & ") AND ((Notes_Archive_Temp.Timestamp)=" & Val(strArchived_Timestamp) & "));" |
| 0185 | Set rsNotes_Archive_Temp = CurrentDb.OpenRecordset(strQuery) |
| 0186 | If Not rsNotes_Archive_Temp.EOF Then |
| 0187 | File_Wanted = "No" |
| 0188 | Debug.Print Now() & " - "; "Archived Note Notes_" & strNotesID & "_" & strArchived_Timestamp & " already exists" |
| 0189 | Else |
| 0190 | rsNotes_Archive_Temp.AddNew |
| 0191 | rsNotes_Archive_Temp.Fields(0) = rsNotes.Fields(0) |
| 0192 | If strTitle = "" Then |
| 0193 | rsNotes_Archive_Temp.Fields(1) = rsNotes.Fields(1) |
| 0194 | Else |
| 0195 | rsNotes_Archive_Temp.Fields(1) = strTitle |
| 0196 | End If |
| 0197 | rsNotes_Archive_Temp.Fields(2) = strNote_Text |
| 0198 | rsNotes_Archive_Temp.Fields(3) = rsNotes.Fields(4) |
| 0199 | rsNotes_Archive_Temp.Fields(4) = rsNotes.Fields(2) |
| 0200 | rsNotes_Archive_Temp.Fields(5) = rsNotes.Fields(5) |
| 0201 | rsNotes_Archive_Temp.Fields(6) = Int(File_Timestamp * 1000) |
| 0202 | rsNotes_Archive_Temp.Fields(7) = rsNotes.Fields(7) |
| 0203 | rsNotes_Archive_Temp.Fields(9) = rsNotes.Fields(8) |
| 0204 | rsNotes_Archive_Temp.Fields(10) = rsNotes.Fields(9) |
| 0205 | rsNotes_Archive_Temp.Fields(11) = strArchived_Timestamp |
| 0206 | rsNotes_Archive_Temp.Update |
| 0207 | End If |
| 0208 | End If |
| 0209 | End If |
| 0210 | rsFile_List.MoveNext |
| 0211 | Loop |
| 0212 | Set rsNotes = Nothing |
| 0213 | Set rsNotes_Archive = Nothing |
| 0214 | Set rsNotes_Archive_Temp = Nothing |
| 0215 | End Sub |
| Line-No. / Ref. | Code Line |
| 0001 | Public Function Spider_Note_Convert_Hyperlink(strHyperlink, Hyperlink_Type) |
| 0002 | Dim strHyperlink_Local As String |
| 0003 | Dim h As Long |
| 0004 | Dim i As Long |
| 0005 | Dim j As Long |
| 0006 | Dim k As Long |
| 0007 | Dim m As Long |
| 0008 | strHyperlink_Local = strHyperlink |
| 0009 | Hyperlink_Type = "Unknown" |
| 0010 | i = InStr(strHyperlink_Local, "PaperSummary_") |
| 0011 | If i > 0 Then |
| 0012 | Hyperlink_Type = "Paper" |
| 0013 | i = InStr(i + 1, strHyperlink_Local, "PaperSummary_") |
| 0014 | If i > 0 Then |
| 0015 | i = i + Len("PaperSummary_") |
| 0016 | j = InStr(i, strHyperlink_Local, ".") |
| 0017 | If i > 0 Then |
| 0018 | strHyperlink_Local = "+P" & Mid(strHyperlink_Local, i, j - i) & "P+" |
| 0019 | Else |
| 0020 | Hyperlink_Type = Hyperlink_Type & " - Defective" |
| 0021 | End If |
| 0022 | Else |
| 0023 | Hyperlink_Type = Hyperlink_Type & " - Defective" |
| 0024 | End If |
| 0025 | Else |
| 0026 | i = InStr(strHyperlink_Local, "BookSummary_") |
| 0027 | If i > 0 Then |
| 0028 | Hyperlink_Type = "Book" |
| 0029 | i = InStr(i + 1, strHyperlink_Local, "BookSummary_") |
| 0030 | If i > 0 Then |
| 0031 | i = i + Len("BookSummary_") |
| 0032 | j = InStr(i, strHyperlink_Local, ".") |
| 0033 | If i > 0 Then |
| 0034 | strHyperlink_Local = "+B" & Mid(strHyperlink_Local, i, j - i) & "B+" |
| 0035 | Else |
| 0036 | Hyperlink_Type = Hyperlink_Type & " - Defective" |
| 0037 | End If |
| 0038 | Else |
| 0039 | Hyperlink_Type = Hyperlink_Type & " - Defective" |
| 0040 | End If |
| 0041 | Else |
| 0042 | i = InStr(strHyperlink_Local, "/Notes_") |
| 0043 | If i > 0 Then |
| 0044 | Hyperlink_Type = "Note" |
| 0045 | h = InStr(strHyperlink_Local, "#") |
| 0046 | j = InStr(strHyperlink_Local, "NotesPrint") |
| 0047 | k = InStr(strHyperlink_Local, "Jump") |
| 0048 | m = InStr(strHyperlink_Local, "TARGET") |
| 0049 | If j + k + h + m > 0 Then |
| 0050 | Hyperlink_Type = Hyperlink_Type & " - Defective" |
| 0051 | Else |
| 0052 | i = InStr(i + 1, strHyperlink_Local, "/Notes_") |
| 0053 | If i > 0 Then |
| 0054 | i = i + Len("/Notes_") |
| 0055 | j = InStr(i, strHyperlink_Local, "_") |
| 0056 | If i > 0 Then |
| 0057 | If j = 0 Then 'Isn't a link to an archived note |
| 0058 | j = InStr(i, strHyperlink_Local, ".") |
| 0059 | End If |
| 0060 | strHyperlink_Local = "++" & Mid(strHyperlink_Local, i, j - i) & "++" |
| 0061 | Else |
| 0062 | Hyperlink_Type = Hyperlink_Type & " - Defective" |
| 0063 | End If |
| 0064 | Else |
| 0065 | Hyperlink_Type = Hyperlink_Type & " - Defective" |
| 0066 | End If |
| 0067 | End If |
| 0068 | End If |
| 0069 | End If |
| 0070 | End If |
| 0071 | If Hyperlink_Type = "Unknown" Or InStr(Hyperlink_Type, "Defective") > 0 Then |
| 0072 | Spider_Note_Convert_Hyperlink = "No" |
| 0073 | Else |
| 0074 | Spider_Note_Convert_Hyperlink = "Yes" |
| 0075 | End If |
| 0076 | strHyperlink = strHyperlink_Local |
| 0077 | End Function |
| Line-No. / Ref. | Code Line |
| 0001 | Public Function Spider_Note_Remove_Hyperlinks(strText) |
| 0002 | Dim x As Long |
| 0003 | Dim Y As Long |
| 0004 | Dim z As String |
| 0005 | Dim strText_Local As String |
| 0006 | Dim strText_End As String |
| 0007 | Dim strHyperlink As String |
| 0008 | Dim strMarker As String |
| 0009 | Dim strLinkEnd As String |
| 0010 | Dim strPrefix As String |
| 0011 | Dim strAffix As String |
| 0012 | Dim Hyperlink_Type As String |
| 0013 | Dim i As Integer |
| 0014 | If Len(strText) = 0 Then |
| 0015 | Spider_Note_Remove_Hyperlinks = "Not Found" |
| 0016 | Exit Function |
| 0017 | End If |
| 0018 | i = 0 |
| 0019 | strPrefix = " |
| 0020 | strAffix = ">" |
| 0021 | strLinkEnd = "" |
| 0022 | strText_Local = strText |
| 0023 | x = 1 |
| 0024 | x = InStr(x, strText_Local, strPrefix) |
| 0025 | Spider_Note_Remove_Hyperlinks = "Not Found" |
| 0026 | Do While x > 0 |
| 0027 | Spider_Note_Remove_Hyperlinks = "Found" |
| 0028 | Y = InStr(x + 1, strText_Local, strAffix) |
| 0029 | 'Watch out for false positives in finding strPrefix |
| 0030 | If Y = 0 Then |
| 0031 | x = x + 1 |
| 0032 | Else |
| 0033 | strHyperlink = Mid(strText_Local, x, Y - x) |
| 0034 | OK = Spider_Note_Convert_Hyperlink(strHyperlink, Hyperlink_Type) |
| 0035 | If OK = "Yes" Then |
| 0036 | z = InStr(Y + 1, strText_Local, strLinkEnd) |
| 0037 | If z > 0 Then |
| 0038 | If Hyperlink_Type = "Note" Then |
| 0039 | strMarker = Mid(strText_Local, Y + 1, z - Y - 1) |
| 0040 | strHyperlink = strMarker & strHyperlink |
| 0041 | End If |
| 0042 | z = z + Len(strLinkEnd) |
| 0043 | 'Remove the superscript/subscripts |
| 0044 | If Left(strHyperlink, 2) = " |
| 0045 | i = InStr(strHyperlink, ">") |
| 0046 | i = InStr(i + 1, strHyperlink, ">") |
| 0047 | strHyperlink = Mid(strHyperlink, i + 1, Len(strHyperlink)) |
| 0048 | End If |
| 0049 | If Mid(strText_Local, z, 5) = "" Then |
| 0050 | Y = InStr(z + 1, strText_Local, "") |
| 0051 | If Y > 0 And Y - z < 10 Then |
| 0052 | z = Y + 6 |
| 0053 | End If |
| 0054 | Else |
| 0055 | If Mid(strText_Local, z, 5) = "" Then |
| 0056 | Y = InStr(z + 1, strText_Local, "") |
| 0057 | If Y > 0 And Y - z < 10 Then |
| 0058 | z = Y + 6 |
| 0059 | End If |
| 0060 | End If |
| 0061 | End If |
| 0062 | strText_End = Mid(strText_Local, z, Len(strText_Local)) |
| 0063 | strText_Local = Left(strText_Local, x - 1) & strHyperlink & strText_End |
| 0064 | End If |
| 0065 | End If |
| 0066 | End If |
| 0067 | x = InStr(x + 1, strText_Local, strPrefix) |
| 0068 | Loop |
| 0069 | strText = strText_Local |
| 0070 | End Function |