不幸的是,我们不能在单个 Access SQL 查询中执行此操作,因此我们使用 VBA:

Sub ReplaceAccentsInTable2()
'
Dim rst As dao.Recordset
Dim rst1 As dao.Recordset
'
Set rst = CurrentDb.OpenRecordset("table2")
'
' replace first by country specific alphabet:
'
Do While (Not rst.EOF)
'
Set rst1 = CurrentDb.OpenRecordset("SELECT txtOld, txtreplace" _
& " FROM table1 WHERE (country='" & rst!Country & "');")
'
rst.Edit
'
While (Not rst1.EOF)
rst!Firstname = Replace(rst!Firstname, rst1!txtOld, rst1!txtreplace, , , vbBinaryCompare)
rst!Address = Replace(rst!Address, rst1!txtOld, rst1!txtreplace, , , vbBinaryCompare)
rst1.MoveNext
Wend
'
rst.Update
rst.MoveNext
'
Loop
'
' replace then "all" alphabet: this is useful for Norway, as â is not set in table1:
'
Set rst1 = CurrentDb.OpenRecordset("SELECT txtOld, txtreplace" _
& " FROM table1 WHERE (country='all');")
'
rst.MoveFirst
'
Do While (Not rst.EOF)
'
rst.Edit
rst1.MoveFirst
'
While (Not rst1.EOF)
rst!Firstname = Replace(rst!Firstname, rst1!txtOld, rst1!txtreplace, , , vbBinaryCompare)
rst!Address = Replace(rst!Address, rst1!txtOld, rst1!txtreplace, , , vbBinaryCompare)
rst1.MoveNext
Wend
'
rst.Update
rst.MoveNext
'
Loop
'
' close ADO objects:
'
rst1.Close
Set rst1 = Nothing
'
rst.Close
Set rst = Nothing
'
End Sub
结果表2在这里:
