This follows my closed Access SQL question from the other day. I restructured my DB, got the DoWhile working and I’m testing a simple UPDATE statement to ensure I get the results I want before adding to larger VBA. I have 4 comments in the comments table, CMT long field and I want to update the word “slow” in the mariner table, field KW, WHERE comments.cmt Like ‘%slow&’ The mechanics work, but it updates 0 records. The Access design view works perfectly and updates the 2 rows. The SQL string in VBA updates 0. I’ve attached the design view image, SQL string code, comments table image of 4 records. What am I missing if Design View correctly updates only the 2, and SQL updates 0.
Dim sql As String
sql = "UPDATE Comments LEFT JOIN Mariners ON Comments.RefNum = Mariners.Refnum " & _
" SET Mariners.KW = 'slow' " & _
" WHERE comments.cmt Like '%Slow%'"
DoCmd.RunSQL sql
Because design view updates the mariner table with the 2 rows containing the word ‘slow’ and ignores the other 2 rows, I assumed the SQL statement would do the same. The SQL statement will be part of a larger DO WHILE and FOR NEXT VBA keyword search of a record set of 1000 records. So while a simple UPDATE, the looping and keyword search will be more extensive (and the word “slow” will be read from a recordset.
dCharles is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.