Results 1 to 4 of 4

Thread: VBA SQL

  1. #1
    Star Lounger
    Join Date
    Oct 2003
    Posts
    77
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I know there is probably a really simple fix to this but its beyond my current capabilities of sql in vba.

    When I run this - its asks for NOTE and ID values. It works fine if I enter the values again but its supposed to be setting those values from fields on a form.

    Any help would be appreciated...thanks!

    Steve

    Dim sql_string As String
    Dim NOTE As String
    Dim ID As Variant

    NOTE = Forms!frm_CREATE_TEMP_NOTE![C_NOTES]
    ID = Forms!frm_CREATE_TEMP_NOTE![TEMP_NOTES_ID]

    sql_string = "UPDATE tbl_TEMP_FIELD_NOTES SET [C_NOTES] = NOTE WHERE [TEMP_NOTES_ID] = ID ;"

    DoCmd.RunSQL sql_string

  2. #2
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts
    Quote Originally Posted by bigsteve520 View Post
    I know there is probably a really simple fix to this but its beyond my current capabilities of sql in vba.

    When I run this - its asks for NOTE and ID values. It works fine if I enter the values again but its supposed to be setting those values from fields on a form.

    Any help would be appreciated...thanks!

    Steve

    Dim sql_string As String
    Dim NOTE As String
    Dim ID As Variant

    NOTE = Forms!frm_CREATE_TEMP_NOTE![C_NOTES]
    ID = Forms!frm_CREATE_TEMP_NOTE![TEMP_NOTES_ID]

    sql_string = "UPDATE tbl_TEMP_FIELD_NOTES SET [C_NOTES] = NOTE WHERE [TEMP_NOTES_ID] = ID ;"

    DoCmd.RunSQL sql_string
    You can't put NOTE and ID inside the quotes. You have 2 choices:

    sql_string = "UPDATE tbl_TEMP_FIELD_NOTES SET [C_NOTES] = forms!frm_create_temp_note!c_Notes WHERE [TEMP_NOTES_ID] =forms!frm_create_temp_note!temp_notes_id ;"

    Or

    sql_string = "UPDATE tbl_TEMP_FIELD_NOTES SET [C_NOTES] = " & chr(34) & NOTE & chr(34) & " WHERE [TEMP_NOTES_ID] = " & ID (assume ID is numeric)
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  3. #3
    Star Lounger
    Join Date
    Oct 2003
    Posts
    77
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks - this works except for the NOTE field. If it is larger than 255 chacters...it cuts off the end replacing it with some funky characters.

    The NOTES field in the table I am updating is a Memo Field and the NOTE field on the form is an unbound text box.

    I understand the limitations with using straight append queries and memo fields but I thought using VBA SQL was a way around it.

    Is it possible to update or append a memo field this way?

    Thanks again!

    Steve

  4. #4
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    I just copied your code into a little test database, and the code happily put any text into the Note field without any truncating or funky characters.

    So I wonder what is different for me?

    Truncation of Memo fields is a commonly reported problem, but none of the STANDARD EXPLANATIONS seem to apply here.
    Regards
    John



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •