忘れないために

自分の備忘録

Function getBCategId(title As String) As String
    Dim db As DAO.Database
    Set db = CurrentDb
    Dim rs As DAO.Recordset
    
    Dim id As String
    Dim colmun As String
    Dim result As String
    
    result = ""
    
    Set rs = db.OpenRecordset("テーブル名")
    
    Do Until rs.EOF
        id = rs.Fields("ID")
        colmun = rs.Fields("colmun")
        
        temp = Split(colmun, " ")
        
        For i = LBound(temp) To UBound(temp)
           
           If temp(i) = "" Then
               Exit For
           End If
           
           If InStr(title, temp(i)) > 1 Then
                result = id
                GoTo next_i
           Else
              If result <> "" Then
                result = ""
              End If
            
              Exit For
           End If
next_i:
        Next i
        
        If result <> "" Then
            Exit Do
        End If
        
        rs.MoveNext
        
    Loop
    If result = "" Then
       result = "449"
    End If
    
    getBCategId = result
End Function