Solved

alter word removal function

Posted on 2014-09-03
3
214 Views
Last Modified: 2014-09-08
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

0
Comment
Question by:PeterBaileyUk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 

Author Comment

by:PeterBaileyUk
ID: 40300960
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

0
 
LVL 50

Accepted Solution

by:
Vitor Montalvão earned 500 total points
ID: 40303106
You have a Replace function that can do what you want.

The full syntax is: Replace ( string1, find, replacement, [start, [count, [compare]]] )

Example:
Replace("This is a phrase with some words", "some", "FEW")

Result --->"This is a phrase with FEW words"

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question