Link to home
Start Free TrialLog in
Avatar of PeterBaileyUk
PeterBaileyUk

asked on

alter word removal function

I have a function that an expert helped me on but I need to amend it so that rather than extracting unwanted words it will substitute the word instead.

I am not seeing in my head how to do this.

I am in vba
Function replacemulti(Strin As String, Client As String, Marque As String) As String

    Dim Stroutput As String
    Dim ClientWords() As String
    Dim x As Integer

    Dim dbs As DAO.Database
    Dim rstWordExtractions As DAO.Recordset
    Dim rstWordExceptions As DAO.Recordset

    'create recordset of excluded words and of exception words
    Set dbs = CurrentDb
    Set rstWordExtractions = dbs.OpenRecordset("QryAliaswords", dbOpenDynaset)
    Set rstWordExceptions = dbs.OpenRecordset("TblExceptions", dbOpenDynaset)
    Dim strCriteria As String




Dim strCriteriaClient As String
Dim strCriteriaException
Dim LogicCriteria As Boolean
Debug.Print "replacemultiinput: " & Strin
LogicCriteria = False
    'split words
    ClientWords = Split(Trim(Strin))

    For x = LBound(ClientWords) To UBound(ClientWords)



        strCriteriaException = "[wordexception] = " & LogicCriteria
        strCriteria = "[sdesc] = '" & ClientWords(x) & "'"
        strCriteriaClient = "[sClient] = '" & Client & "'"
        
        
        strCriteria = strCriteria & " And " & strCriteriaClient & " And " & strCriteriaException
     
        rstWordExtractions.FindFirst strCriteria
        Debug.Print strCriteria
        If rstWordExtractions.NoMatch Then
            Stroutput = Stroutput & " " & ClientWords(x)
            Debug.Print "multi output :" & Stroutput
        Else
        
            rstWordExceptions.FindFirst strCriteria
            Debug.Print strCriteria
            If rstWordExceptions.NoMatch Then
                'ignore this word, it is in the
                'Extract list but not in the Exempt list
            Else
                Stroutput = Stroutput & " " & ClientWords(x)
                Debug.Print "multi output :" & Stroutput
            End If
        End If

    Next x

    
    replacemulti = Trim(Stroutput)
   
  
ProcExit:
   rstWordExceptions.Close
   Set rstWordExceptions = Nothing
   rstWordExtractions.Close
   Set rstWordExtractions = Nothing
   Exit Function
ProcError:
   MsgBox Err.Number & vbCrLf & Err.Description, , "replaceMulti"
   Resume ProcExit
End Function

Open in new window

Avatar of PeterBaileyUk
PeterBaileyUk

ASKER

I think I cracked it by altering this:
  If rstWordExceptions.NoMatch Then
                'ignore this word, it is in the
                'Extract list but not in the Exempt list
                Stroutput = Stroutput & " " & "RemovedMult" 'added this line
            Else
                Stroutput = Stroutput & " " & ClientWords(x)
                Debug.Print "multi output :" & Stroutput
            End If

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Vitor Montalvão
Vitor Montalvão
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial