'MacroName:GetControlledLinks 'MacroDescription:Find and save AF records for all controlled headings in a record 'Written by: Joel Hahn, Niles Public Library District 'Last modified: 8 November 2005 Declare Function StripSubfields(sData) As String Declare Function FindMatch(CS as Object, sIndex, sTerm, sData, sTitle, sONum) As Integer Declare Function PartialControlledHandler(CS, sIndex, sData, sTitle, sONum) As Integer Sub Main Dim CS As Object On Error Resume Next Set CS = GetObject(,"Connex.Client") On Error GoTo 0 If CS Is Nothing Then Set CS = CreateObject("Connex.Client") End If CurRow = CS.CursorRow bool = CS.GetField("245", 1, sTitle) bool = CS.GetFixedField("OCLC", sONum) i = 1 Do Until CS.GetFieldLine(i, sField) = FALSE bool = CS.IsHeadingControlled(i) If bool <> FALSE Then 'MsgBox "|" & Left(sField, 3) & "|" & Mid(sField, 6) & "|" If Right(sField, 1) = "." Then sField = Left(sField, Len(sField)-1) sSearchTerm = StripSubfields(Mid(sField, 6)) Select Case Left(sField, 3) Case "100", "700", "800" '= personal name bool = FindMatch(CS, "pn:", sSearchTerm, Mid(sField, 6), sTitle, sONum) If bool = FALSE And Instr(sField, Chr(223)) > 0 Then bool = PartialControlledHandler(CS, "pn:", sField, sTitle, sONum) End If Case "110", "710", "810" '= corporate name bool = FindMatch(CS, "co:", sSearchTerm, Mid(sField, 6), sTitle, sONum) If bool = FALSE And Instr(sField, Chr(223)) > 0 Then bool = PartialControlledHandler(CS, "co:", sField, sTitle, sONum) End If Case "111", "711", "811" '= conference name bool = FindMatch(CS, "cn:", sSearchTerm, Mid(sField, 6), sTitle, sONum) If bool = FALSE And Instr(sField, Chr(223)) > 0 Then bool = PartialControlledHandler(CS, "cn:", sField, sTitle, sONum) End If Case "130", "730", "830" '= title bool = FindMatch(CS, "ti:", sSearchTerm, Mid(sField, 6), sTitle, sONum) If bool = FALSE And Instr(sField, Chr(223)) > 0 Then bool = PartialControlledHandler(CS, "ti:", sField, sTitle, sONum) End If Case "600" '= author, plus multi-controled subjects bool = FindMatch(CS, "pn:", sSearchTerm, Mid(sField, 6), sTitle, sONum) If bool = FALSE And Instr(sField, Chr(223)) > 0 Then bool = PartialControlledHandler(CS, "pn:", sField, sTitle, sONum) End If Case "610" '= author, plus multi-controled subjects ' nNumRecs = CS.Search("AF", "co:" & sSearchTerm) bool = FindMatch(CS, "co:", sSearchTerm, Mid(sField, 6), sTitle, sONum) If bool = FALSE And Instr(sField, Chr(223)) > 0 Then bool = PartialControlledHandler(CS, "co:", sField, sTitle, sONum) End If Case "611" '= author, plus multi-controled subjects ' nNumRecs = CS.Search("AF", "cn:" & sSearchTerm) bool = FindMatch(CS, "cn:", sSearchTerm, Mid(sField, 6), sTitle, sONum) If bool = FALSE And Instr(sField, Chr(223)) > 0 Then bool = PartialControlledHandler(CS, "cn:", sField, sTitle, sONum) End If Case "630" '= title, plus multi-controlled subjects ' nNumRecs = CS.Search("AF", "ti:" & sSearchTerm) bool = FindMatch(CS, "ti:", sSearchTerm, Mid(sField, 6), sTitle, sONum) If bool = FALSE And Instr(sField, Chr(223)) > 0 Then bool = PartialControlledHandler(CS, "ti:", sField, sTitle, sONum) End If Case "650" '= topical subject, plus multi-controlled subjects ' nNumRecs = CS.Search("AF", "su:" & sSearchTerm) bool = FindMatch(CS, "su:", sSearchTerm, Mid(sField, 6), sTitle, sONum) If bool = FALSE And Instr(sField, Chr(223)) > 0 Then bool = PartialControlledHandler(CS, "su:", sField, sTitle, sONum) End If Case "651" '= geographic subject, plus multi-controlled subjects ' nNumRecs = CS.Search("AF", "gg:" & sSearchTerm) bool = FindMatch(CS, "gg:", sSearchTerm, Mid(sField, 6), sTitle, sONum) If bool = FALSE And Instr(sField, Chr(223)) > 0 Then bool = PartialControlledHandler(CS, "gg:", sField, sTitle, sONum) End If End Select End If i = i + 1 Loop CS.CursorRow = CurRow End Sub Function StripSubfields(sData) As String Do While InStr(sData, Chr(223)) place = InStr(sData, Chr(223)) sData = RTrim(Left(sData, place-1)) & " " & LTrim(Mid(sData, place+2)) Loop StripSubfields = sData End Function Function FindMatch(CS As Object, sIndex, sTerm, sData, sTitle, sONum) As Integer nNumRecs = CS.Search("AF", sIndex & sTerm) If nNumRecs = 1 Then bool = CS.GetField("1..", 1, sCheckField) If Mid(sCheckField, 6) = sData Or Mid(sCheckField, 6) = sData & "." Then FindMatch = TRUE bool = CS.SetMyStatus("From " & sONum) nSaveFileNumber = CS.SaveToLocalFile(TRUE, FALSE) End If bool = CS.CloseRecord(FALSE) Exit Function ElseIf nNumRecs > 1 Then 'nNumRecs = CS.SearchList("Illinois " & Chr(223) & "b Dept.", "Description", FALSE) bool = CS.GetFirstItem Do bool = CS.GetField("1..", 1, sCheckField) If Mid(sCheckField, 6) = sData Or Mid(sCheckField, 6) = sData & "." Then FindMatch = TRUE bool = CS.SetMyStatus("From #" & sONum) nSaveFileNumber = CS.SaveToLocalFile(TRUE, FALSE) Exit Do End If Loop While CS.GetNextItem <> FALSE bool = CS.CloseRecord(FALSE) bool = CS.CloseList End If End Function Function PartialControlledHandler(CS, sIndex, sData, sTitle, sONum) As Integer i = 1 : nCountSubs = 1 Do If Mid(sData, i, 1) = Chr(223) Then nCountSubs = nCountSubs + 1 i = i + 1 Loop Until i >= Len(sData) nSubCount = 1 sNewField = sData Do i = Len(sNewField) Do i = i - 1 Loop Until Mid(sNewField, i, 1) = Chr(223) Or i <= 7 If Mid(sNewField, i, 1) = Chr(223) Then sNewField = RTrim(Left(sNewField, i-1)) sNewSearchTerm = StripSubfields(Mid(sNewField, 6)) bool = FindMatch(CS, sIndex, sNewSearchTerm, Mid(sNewField, 6), sTitle, sONum) Else Exit Do End If nSubCount = nSubCount + 1 Loop Until bool <> FALSE Or nSubCount >= nCountSubs End Function