Solved

wrong case in the result of Replace Function

Posted on 2013-05-16
2
425 Views
Last Modified: 2013-05-17
I have a small function to screen for French-accented characters and replace them with unaccented English characters. It works OK for uppercase characters, but it replaces a lower-case French character with the upper-case English character.

The specified replacement character IS lower case, so it seems that VBA is making the case decision in spite of what is specified in my code.

I am attaching a small database, ReplaceProblem.accdb with one module in it that shows everything about the problem.

I am also attaching two screen shots of the erroneous results.
ReplaceProblem.accdb
CleanChar-problem.JPG
CleanChar-problem2.JPG
0
Comment
Question by:dmaclean2
2 Comments
 
LVL 17

Accepted Solution

by:
Chris Millard earned 500 total points
ID: 39173972
I've revised the function a little so that the REPLACE function uses vbBinaryCompare. Try this:-

Public Function CleanChar(inString As String) As String
On Error GoTo HandleError
Dim i As Long
Dim CleanTemp As String
    CleanTemp = inString
    For i = 1 To CleanCharMax
            CleanTemp = Replace(CleanTemp, inProbChar(i), outCleanChar(i), , , vbBinaryCompare)
    Next i
    CleanChar = CleanTemp
ExitProc:
    Exit Function
HandleError:
    MsgBox Err.Number & " " & Err.Description & " in CleanChar", vbOKOnly + vbCritical, ModName
    Resume ExitProc
End Function

Open in new window

0
 

Author Closing Comment

by:dmaclean2
ID: 39174061
Perfect solution. And I learned something important about Replace options.
Thanks much, roybridge!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

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…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
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 …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

743 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

12 Experts available now in Live!

Get 1:1 Help Now