Solved

alter word removal function

Posted on 2014-09-03
3
209 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 45

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

747 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

13 Experts available now in Live!

Get 1:1 Help Now