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
Solved

alter word removal function

Posted on 2014-09-03
3
212 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
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 48

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

808 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