G
Guest
Seemed like the WHERE clause flaked as if it wasn’t' there at all; every
record in the table was updated.
Does any one know what went wrong? Here is the code:
Dim rst As New adodb.Recordset
rst.Open ("UPDATE Comments SET Comments.Notes = '" &
Trim(Replace(Me.txtNotes.Value, "'", "''"))"' WHERE (((Comments.ID)= " &
Me.lstNotes.Column(0, Me.lstNotes.ListIndex + 1) & "));"),
CurrentProject.Connection, adOpenStatic, adLockOptimistic
Explanation:
Columns in Comments table are: ID, Date, UserID, Notes.
lstNotes is a list box that show list of user's existing notes. User select
a note to edit. Selected note is edited in a text box named txtNotes. Save
button runs above code.
As a safety precaution, I modified the code to as follows but still don't
know what caused the disaster:
Dim myId As Long, myNote As String
myId = Val(Me.lstNotes.Column(0, Me.lstNotes.ListIndex + 1))
myNote = Trim(Replace(Me.txtNotes.Value, "'", "''"))
If myId <> 0 Then
DoCmd.RunSQL "UPDATE Comments SET Comments.Notes = '" & myNote & "' WHERE
Comments.ID= " & myId & ";"
end if
record in the table was updated.
Does any one know what went wrong? Here is the code:
Dim rst As New adodb.Recordset
rst.Open ("UPDATE Comments SET Comments.Notes = '" &
Trim(Replace(Me.txtNotes.Value, "'", "''"))"' WHERE (((Comments.ID)= " &
Me.lstNotes.Column(0, Me.lstNotes.ListIndex + 1) & "));"),
CurrentProject.Connection, adOpenStatic, adLockOptimistic
Explanation:
Columns in Comments table are: ID, Date, UserID, Notes.
lstNotes is a list box that show list of user's existing notes. User select
a note to edit. Selected note is edited in a text box named txtNotes. Save
button runs above code.
As a safety precaution, I modified the code to as follows but still don't
know what caused the disaster:
Dim myId As Long, myNote As String
myId = Val(Me.lstNotes.Column(0, Me.lstNotes.ListIndex + 1))
myNote = Trim(Replace(Me.txtNotes.Value, "'", "''"))
If myId <> 0 Then
DoCmd.RunSQL "UPDATE Comments SET Comments.Notes = '" & myNote & "' WHERE
Comments.ID= " & myId & ";"
end if