Hi all, I am having difficulties working though this loop problem - for some reason, I am missing a vital concept!
BACKGROUND
I am trying to copy certain fields from one record to another using a command button on a form.
In the OnClick event, I set a SQL string as a DAO recordset and then created a SQL UPDATE to add the records.
Everything was working fine and dandy until I came across text or memo fields which contain apostrophes. These are breaking my SQL strings.
This leads us to my current dilemma.
PROBLEM
I need to loop through the fields in the recordset I had created and replace all apostrophes with double apostrophes (please let me know if that logic is false - I had read that was the answer).
Here is one of the... 15? versions I had tried to accomplish this:
I thought I was looping through all the fields and replacing any apostrophes in text/memo fields. Because there is only ever going to be one record, the EOF should trip after the first time, but it does not.
If someone could let me know what I am doing wrong, it would be greatly appreciated!
BACKGROUND
I am trying to copy certain fields from one record to another using a command button on a form.
In the OnClick event, I set a SQL string as a DAO recordset and then created a SQL UPDATE to add the records.
Everything was working fine and dandy until I came across text or memo fields which contain apostrophes. These are breaking my SQL strings.
This leads us to my current dilemma.
PROBLEM
I need to loop through the fields in the recordset I had created and replace all apostrophes with double apostrophes (please let me know if that logic is false - I had read that was the answer).
Here is one of the... 15? versions I had tried to accomplish this:
Code:
Dim fld As Field
Do Until rs.EOF
With rs
.MoveLast
.MoveFirst
For Each fld In .Fields
If fld.Type = dbText Or fld.Type = dbMemo Then
rs.Edit
fld.Value = Replace(fld.Value & "", "'", "''")
End If
Next fld
End With
Loop
If someone could let me know what I am doing wrong, it would be greatly appreciated!