Skip to content
Loading
0
  • 0
    Jefferson - That line of code gives me a syntax error, with or w/o a period between rs and [IDER].  The column name is IDER in tblCensus4 and it is an Autonummuber data type. In tblCensus1Sorted the column name is IDER and it is an Number data type
    0
  • Jefferson S. Motta
    0
    Ups,
     
    now I see:
     
    we are not respecting the SQL statement, try this and tell me please:
     
     
    1. SQL = "UPDATE tblCensus4 SET tblCensus4.[Desc] = CONCAT(tblCensus4.[Desc], '" & Chr(13) & Chr(10) & strvalue & "') WHERE " & CStr(rs[IDER]) & " = tblCensus4.[IDER];"   
     
    0
  • 0
    Jefferson - I got the code in black to work based on a lot of help from Stephan Landau in the Microsoft Accss Facebook group:
     
    Dim strvalue As String
    :
    SQL = "UPDATE tblCensus4 SET tblCensus4.[Desc] = tblCensus4.[Desc] & Chr(13) & Chr(10) & strvalue & " WHERE " & CStr(rs.[IDER]) & " = tblCensus4.[IDER];" 
     
    Dim numvalue As Integer
    numvalue = rs.IDER.Value
    :
    SQL = "UPDATE tblCensus4 SET tblCensus4.[Desc] = tblCensus4.[Desc] & Chr(13) & Chr(10) & """ & strvalue & """ WHERE tblCensus4.[IDER]=" & numvalue

    I appreciate you taking the time to help me as well.
    0
  • Jefferson S. Motta
    0
    THIS IS NOT A VALID SQL STAMENT:
    1. SQL = "UPDATE tblCensus4 SET tblCensus4.[Desc] = tblCensus4.[Desc] & Chr(13) & Chr(10) & """ & strvalue & """ WHERE tblCensus4.[IDER]=" & numvalue  
    YOU NEED to UPDATE THE [Desc] FIELD WITH A VALID SQL EXPRESSION, SO YOU NEED USE " ' " IN THE VALUE CONTENT TO USE THE SET. 
    1. tblCensus4.[Desc] = CONCAT(tblCensus4.[Desc], '" & Chr(13) & Chr(10) & strvalue & "')  
     PLEASE, DEBUG THE CODE FROM THE FIRST LINE AND SHOW ME THE VALUE FROM SQL VAR.
     
    * SORRY THE CAPS.
     
    Best,
     
    Jeff
    0
  • 0
    Jefferson - I am not an experienced VBA programmer.  All I know is that the code works.  Here are the first several passes though the recordset from Debug.Print SQL; Var:
     
    UPDATE tblCensus4 SET tblCensus4.[Desc] = tblCensus4.[Desc] & Chr(13) & Chr(10) & "Ida Louise Wagner" WHERE tblCensus4.[IDER]=168
    UPDATE tblCensus4 SET tblCensus4.[Desc] = tblCensus4.[Desc] & Chr(13) & Chr(10) & "June Barbara Quigley" WHERE tblCensus4.[IDER]=168
    UPDATE tblCensus4 SET tblCensus4.[Desc] = tblCensus4.[Desc] & Chr(13) & Chr(10) & "Ida Louise Wagner" WHERE tblCensus4.[IDER]=179
    UPDATE tblCensus4 SET tblCensus4.[Desc] = tblCensus4.[Desc] & Chr(13) & Chr(10) & "Francis Albert (Frank) Quigley" WHERE tblCensus4.[IDER]=179
    UPDATE tblCensus4 SET tblCensus4.[Desc] = tblCensus4.[Desc] & Chr(13) & Chr(10) & "June Barbara Quigley" WHERE tblCensus4.[IDER]=179
    UPDATE tblCensus4 SET tblCensus4.[Desc] = tblCensus4.[Desc] & Chr(13) & Chr(10) & "Robert Weston (Bob) Quigley" WHERE tblCensus4.[IDER]=179
    UPDATE tblCensus4 SET tblCensus4.[Desc] = tblCensus4.[Desc] & Chr(13) & Chr(10) & "Theresa Margaret Anderson" WHERE tblCensus4.[IDER]=393
    0
  • Jefferson S. Motta
    0
    Hello, sorry to tell but you don't know how SQL works   you are not getting error with VBA, but not knowing the SQL language.   to execute successfully your query it's must looks like:  
    1. "UPDATE tblCensus4 SET tblCensus4.[Desc] = '" & tblCensus4.[Desc] & Chr(13) & Chr(10) & "Ida Louise Wagner" & "' WHERE tblCensus4.[IDER]=168"  
    You must have the new value to update a column text surrounding by " ' ".
     
    Example:
    "UPDATE myTable SET nameCOlumn = 'My Value Column';"
    the "My Value Column" must begin and ends with "'".
    And for safety you need add a replace for column name like : Replace(valueFromAnyWhere, "'", "''");
    Explanation: if a name contais a "'" it will generate error
    THIS GENERATES AN ERROR:
    "UPDATE tblCensus4 SET tblCensus4.[Desc] = '" & tblCensus4.[Desc] & Chr(13) & Chr(10) & "Ida Sant'Anna Louise Wagner" & "' WHERE tblCensus4.[IDER]=168"
    THIS WORKS:
    "UPDATE tblCensus4 SET tblCensus4.[Desc] = '" & tblCensus4.[Desc] & Chr(13) & Chr(10) & "Ida Sant''Anna Louise Wagner" & "' WHERE tblCensus4.[IDER]=168"
    0
  • 0
    Jefferson,
     
    I'm not sure how to respond to you.  All I know is that the code as written, and provided to be by a knowledgeable VBA programmer, does work properly and does update my table the way I wanted it to. 
     
    I changed the data to include a record with a single quote, as shown below, but there were no changes in the results.  And then I searched the tables again and found many example of " ' " in the name fields (O'Connor, O'Heron, etc), also with no errors.
     
    Maybe there are two ways to arrive at the same result?
     
    Don
     
    ImmediateView
    UPDATE tblCensus4 SET tblCensus4.[Desc] = tblCensus4.[Desc] & Chr(13) & Chr(10) & "Ida Louise Wagner" WHERE tblCensus4.[IDER]=168
    UPDATE tblCensus4 SET tblCensus4.[Desc] = tblCensus4.[Desc] & Chr(13) & Chr(10) & "June Barbara Quigley" WHERE tblCensus4.[IDER]=168
    UPDATE tblCensus4 SET tblCensus4.[Desc] = tblCensus4.[Desc] & Chr(13) & Chr(10) & "Ida St' Louise Wagner" WHERE tblCensus4.[IDER]=179
    UPDATE tblCensus4 SET tblCensus4.[Desc] = tblCensus4.[Desc] & Chr(13) & Chr(10) & "Francis Albert (Frank) Quigley" WHERE tblCensus4.[IDER]=179
    UPDATE tblCensus4 SET tblCensus4.[Desc] = tblCensus4.[Desc] & Chr(13) & Chr(10) & "June Barbara Quigley" WHERE tblCensus4.[IDER]=179
     
    Results in tblCensus4.[Desc]
    Household Members:
    Francis Eugene (Frank) Quigley
    Ida St' Louise Wagner
    Francis Albert (Frank) Quigley
    Ida St' Louise Wagner
    Francis Albert (Frank) Quigley
    June Barbara Quigley
    0
  • Jefferson S. Motta
    0
    Does it works now?
    0
  • 0
    Jefferson,
     
    Yes it works now as it has always been working with the code you say is "not valid" !
     
    Can we please just agree to disagree?
     
    Don
    0
  • Jefferson S. Motta
    0
    Sorry, I did not understand irony. Does it helped you?
    0
  • Jefferson S. Motta
    0
    Did you try this:
     
    THIS WORKS:
    "UPDATE tblCensus4 SET tblCensus4.[Desc] = '" & tblCensus4.[Desc] & Chr(13) & Chr(10) & "Ida Sant''Anna Louise Wagner" & "' WHERE tblCensus4.[IDER]=168"
     
    0
  • 0
    Jefferson,
     
    Please understand that I have not tried any of your suggestions becuse the code I already had worked, as I have tried to explain to you.
     
    Dim numvalue As Integer
    numvalue = rs.IDER.Value
    :
    SQL = "UPDATE tblCensus4 SET tblCensus4.[Desc] = tblCensus4.[Desc] & Chr(13) & Chr(10) & """ & strvalue & """ WHERE tblCensus4.[IDER]=" & numvalue
     
    Don
    0