RemoveAccents

Wysy

Registered User.
Local time
Today, 00:24
Joined
Jul 5, 2015
Messages
335
Hi,
I have a table that consist some special accent character like letter ő.
This can be entered into table and shows up correctiy in forms. For some pdf savings i wanted to have accentless characters for file name so i found and use a function for this

Public Function RemoveAccents(ByVal inputString As String) As String
Const accentString As String = "ÁáÉéÓóÖöŐőÚúŰű"
Const nonAccentStr As String = "AaEeOoOoOoUuUu"
Dim i As Integer

For i = 1 To Len(accentString)
inputString = Replace(inputString, Mid(accentString, i, 1), _
Mid(nonAccentStr, i, 1), , , vbBinaryCompare)
Next i

RemoveAccents = inputString

End Function
This works perfectly except with character ő. If data is taken from form control it fails however if i use RemoveAccents("ő") it works.
Why? It seems Access automatically changes something despite it shows up correctly in table/form. Interestingly Dlookup function also fails if character ő is used in the where condition.
Thank you
 
I have a client who has the same requirement. I created a table

Target..Alias..AsciiTarget
Á...……..A...….193
á...……..a...…..225
É...……..E...…..201
etc

then my equivalent of your removeAccents function which runs through the recordset to do the replace

Code:
while not .eof
  mystr=replace(mystr,!Target,!Alias)
  .movenext
wend
point is my table contains the ő char and does not cause a problem

I include AsciiTarget because I also have to handle non printing chars and it is a way of 'seeing' the chars. It is also the primary key since (I seem to recall, it was a while ago when I put it together) that that index wouldn't work on the target field
 
i have found a solution. I created a query that simply converts accented characters into non-accented ones using one nested replace statment like:
AccentLess: Replace(Replace(Replace([tbFEDJ].[BS_Name],"ő","o"),"ö","o"),"á","a")
Then in VBA using DLookUp i refer to this query to get the non-accented character for filename. It works.
Thanks
 
only problem with both your solutions is it is hard coded - what if another character requires replacing - You'll need to modify your code.

But if it meets your requirements then hard coding is fine
 
You might find using the Switch function easier than using several nested Replace expressions
 
actually only the character ő and ű caused the problem for the RemoveAccents function all others works fine. Interestingly my solution caused another problem: if Ő was a capital as first letter it was lower case afterward. I solved it now by using StrConv i think this works fine now.
Thank!!!
 

Users who are viewing this thread

Back
Top Bottom