Microsoft
Software
Hardware
Network
Question : Jet-SQL REPLACE bug?
French an ENglish are rather similar and so building an Access translation aide it was natural that I would build SQL statements of roughly the following form :
strSQL = "UPDATE Material SET Material.FR_Word = Replace(Material.FR_Word,'
" & Me!EN & "','" & Me!FR & "')"
strSQL = strSQL & " WHERE Material.ID IN "
strSQL = strSQL & " (SELECT MatID FROM Mat_Word WHERE Mat_Word.WordID = " & Me!ID & ")"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
Context : "Me" is a table, "Word", having "EN" and "FR" fields in addtion to its ID
The idea is for this Word.ID to go through the join table Mat_Word to get to the table Material and perform the replacement within Material.FR_Word
This works just fune except where Me!EN is entirely contained within a longer Me!FR.
For example using two passes to REPLACE English "Citric" and "Acid" for French "Citrique" and "Acide" in "Citric Acid" gives "Citrique Acideeeeee"
Similarilly using two passes to REPLACE "Flammable" and "Liquid" for "Inflammable"" and "Liquide" yields
"InInInInInInflammable Liquideeeeee"
The 6-factor is not 100% consistent. Under differnet From - To combinations I have seen 3 and maybe one other number but with thousands of records I can not remember be sure. 6 "repitions" is by far the most common.
FWIW Access 2003 with the '07 compatibility pack in and everything fully patched, at least up to about 10 days ago.
Is this a real vba / Jet-SQL bug or am I doing something wrong.
Don`t worry about word order. I have a button for that.
I was able to write a vba function to get `round this.
>>>
Public Function x_Replace(strSource, strFrom, strTo) as String
' designed to overcome vb REPLACE fucntion bug
' whereby "Chemist" to "Chimiste" becomes "Chimisteeeeee"
' or "Flammable" to "Inflammable" becomes "InInInInInInflammable"
iPos = 0
fLen = Len(strFrom)
kpos = InStr(strTo, strFrom)
If Not kpos > 0 Then kpos = 0
Do While True
jPos = InStr(iPos + 1, strSource, strFrom)
If jPos > 0 Then
strTEMP = Left(strSource, (jPos - 1))
strTEMP = strTEMP & strTo
strTEMP = strTEMP & Right(strSource, Len(strSource) - jPos - fLen + 1)
strSource = strTEMP
iPos = jPos + kpos
Else
Exit Do
End If
Loop
x_Replace = strTEMP
End Function
<<<
The above is certainly inelegant, was ugly to test sufficiently for my purposes and means that I have use loops at a parent level and invoke x_replace within the loop rather than use the cleaner DoCmd.RunSQL
Points assigned are not so much for me as I have past the need for the solution having a work-around but to satisfy my own curiosity and maybe prevent future hair loss in others. Also E-E has helped me quite a lot in the past so some quid-pro-quo is in order.
Answer : Jet-SQL REPLACE bug?
That is very odd ... can you determine a record where this is sure to occur and then do a Debug.Print of strSQL before you hit the RunSQL call? I'd be interested to see exactly what is happening with this ...
Random Solutions
XP SP3 PROBLEM
trying to read (compressed) laptop disk...
MS Access - First and Last Name field into Full Name
Exchange 2003 Cluster, Event ID: 1080 occurs every three seconds
Crypt some text and Decrypt it
Need help understranding 'WHERE EXISTS' and 'WHERE NOT EXISTS'
How do I display a login banner for RDP users?
storing jpg and retrieving on forms
Remote desktop freezes host computer and stops at HP splash screen on remote computer
Alitris Deployment Solution