Solved

alter word removal function

Posted on 2014-09-03
3
210 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 46

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

911 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now