I am converting data from an 5 tables in an old db to one table in new db (each table shares many common fields and are all customers). Some of the data contains apostrophes. Since the "Replace" keyword is not available in Access 97, I tried using 2 apostrophes as suggested by the help function but I couldn't get it to work. Can you offer any suggestions?
Here's the code I used to test a few fields. It works if I physically remove the apostrophes from my test data. The commented out lines are the ones that don't work when I replaced 1 apostrophe with 2 apostrophes as I thought I read in the help. Thanks for your help.
Sub doconversion()
Dim dbs As Database
Dim rstFr As Recordset
Set dbs = CurrentDb 'this works now
Set rstFr = dbs.OpenRecordset("table_Friends", dbOpenSnapshot)
Do While Not rstFr.EOF
blankfield = "" 'this handles fields we don't have values from the old conversion tables
sql = "INSERT INTO tbl_customer (type_id, company_id, company_temp, ref_lastname, comments) " & _
"VALUES (1,0,'" & blankfield & "','" & Nz(rstFr("emp-last") & "','" & Nz(rstFr("comments") & "')"
' sql = "INSERT INTO tbl_customer (type_id, company_id, company_temp, ref_lastname, comments) " & _
' "VALUES (1,0,''" & blankfield & "'',''" & Nz(rstFr("emp-last") & "'',''" & Nz(rstFr("comments") & "'')"
MsgBox sql
dbs.Execute sql
rstFr.MoveNext
Loop
rstFr.Close
dbs.Close
MsgBox "insert done"
End Sub
Here's the code I used to test a few fields. It works if I physically remove the apostrophes from my test data. The commented out lines are the ones that don't work when I replaced 1 apostrophe with 2 apostrophes as I thought I read in the help. Thanks for your help.
Sub doconversion()
Dim dbs As Database
Dim rstFr As Recordset
Set dbs = CurrentDb 'this works now
Set rstFr = dbs.OpenRecordset("table_Friends", dbOpenSnapshot)
Do While Not rstFr.EOF
blankfield = "" 'this handles fields we don't have values from the old conversion tables
sql = "INSERT INTO tbl_customer (type_id, company_id, company_temp, ref_lastname, comments) " & _
"VALUES (1,0,'" & blankfield & "','" & Nz(rstFr("emp-last") & "','" & Nz(rstFr("comments") & "')"
' sql = "INSERT INTO tbl_customer (type_id, company_id, company_temp, ref_lastname, comments) " & _
' "VALUES (1,0,''" & blankfield & "'',''" & Nz(rstFr("emp-last") & "'',''" & Nz(rstFr("comments") & "'')"
MsgBox sql
dbs.Execute sql
rstFr.MoveNext
Loop
rstFr.Close
dbs.Close
MsgBox "insert done"
End Sub