I can't seem to make this work, as I don't have a query string to apply replace(str, "'", "''"). I am trying to query the database for all records that contain an apostrophe. For example, O'connor, O'Donald, would be returned. After that, the replace function would take out the apostrophes (i.e. Oconnor, and ODonald).
Option Compare Database
Sub testnow()
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim asql As String
Set cnn = CurrentProject.Connection
'asql = "select * from atable"
asql = "Select * from atable where test Like " & """" & "*'*" & """"
Debug.Print (asql)
Set rst = New ADODB.Recordset
With rst
.Open asql, cnn, adOpenDynamic, adLockOptimistic
Do Until .EOF
Debug.Print (rst("test"))
'.Fields("test") = Replace(.Fields("test"), "'", "")
.MoveNext
Loop
End With
MsgBox "connection made"
rst.Close
Set rst = Nothing
End Sub
Option Compare Database
Sub testnow()
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim asql As String
Set cnn = CurrentProject.Connection
'asql = "select * from atable"
asql = "Select * from atable where test Like " & """" & "*'*" & """"
Debug.Print (asql)
Set rst = New ADODB.Recordset
With rst
.Open asql, cnn, adOpenDynamic, adLockOptimistic
Do Until .EOF
Debug.Print (rst("test"))
'.Fields("test") = Replace(.Fields("test"), "'", "")
.MoveNext
Loop
End With
MsgBox "connection made"
rst.Close
Set rst = Nothing
End Sub