gojets1721
Registered User.
- Local time
- Today, 06:38
- Joined
- Jun 11, 2019
- Messages
- 430
I am using the below function which uses a table to replace values.
It works well except I need to add in wildcards and I'm unsure how to do it correctly.
Right now, if I want to replace 'Hello' with 'Hola', it works perfectly.
But I want it to replace any instance of hello, even if it is "Hello1" but it doesn't.
Any idea what to revise in order for it to do that?
	
	
	
		
 It works well except I need to add in wildcards and I'm unsure how to do it correctly.
Right now, if I want to replace 'Hello' with 'Hola', it works perfectly.
But I want it to replace any instance of hello, even if it is "Hello1" but it doesn't.
Any idea what to revise in order for it to do that?
		Code:
	
	
	Public Function ReplaceUDF(ByVal p As Variant) As Variant
    Const SQL As String = "SELECT * FROM tblReplacements ORDER BY Len([Replacement]) DESC;"
    Dim dbs As DAO.Database
    Dim rst As DAO.Recordset
    
    DBEngine.SetOption dbMaxLocksPerFile, 1000000
    
    ReplaceUDF = p
    If Len(p & "") < 1 Then Exit Function
    Set dbs = CurrentDb
    Set rst = dbs.OpenRecordset(SQL, dbOpenSnapshot, dbReadOnly)
    With rst
        .MoveFirst
        Do Until .EOF
            p = Replace$(" " & p & " ", " " & ![Original] & " ", " " & ![Replacement] & " ")
            p = Trim$(p)
            .MoveNext
        Loop
        .Close
    End With
    Set rst = Nothing
    Set dbs = Nothing
    ReplaceUDF = p
End Function 
	 
 
		 
 
		 
 
		