Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    365

    Help with Update Query

    I know this is wrong but can't quite see how to correct it



    Code:
    sql = "Update Tracks set Track = " & "1." & [Track] & " Where tID= " = c - 1
    Track is a Numeric field currently holding 1, 2, 3 etc and I want to change to 1.1, 1.2 etc.
    I tried VAL but didn't work. Access also gives error Microsoft Access can't find the field '|1' referred to in your expression.
    Bit puzzled why it's showing the pipe character.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Why would you need to update the field when this value can be constructed in query or textbox when needed?

    Why do you want to save values like 1.1 and 1.2? Will there be 1.1.1?

    The last = sign should probably be &.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    365
    Quote Originally Posted by June7 View Post
    Why would you need to update the field when this value can be constructed in query or textbox when needed?
    I don't have/want a query or textbox, I want it in the table.

    Why do you want to save values like 1.1 and 1.2? Will there be 1.1.1?
    No. 1 means 1 and .1 means part 1 of 1. Never more.

    The last = sign should probably be &.
    Quite right, but still tells me Access can't find the field '|1'
    Wonder why it thinks that's the field name when it's the field value.
    I'll try Edit with a select query if Update won't work.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Are you running this behind a form that has [Track] as a field in RecordSource?

    I tested this SQL and it works for me.

    If you want to provide db for analysis, follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,938
    Quote Originally Posted by Middlemarch View Post
    I know this is wrong but can't quite see how to correct it

    Code:
    sql = "Update Tracks set Track = " & "1." & [Track] & " Where tID= " = c - 1
    Track is a Numeric field currently holding 1, 2, 3 etc and I want to change to 1.1, 1.2 etc.
    I tried VAL but didn't work. Access also gives error Microsoft Access can't find the field '|1' referred to in your expression.
    Bit puzzled why it's showing the pipe character.
    Why not debug.print it and see what you actually have?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    Update Tracks

    & [Track] &

    Track is a Numeric field
    so which is it? Track or Tracks?

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    CJ, Tracks is table, Track is field.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Suggest you get a real query working then copy the sql and modify that for using in code if that's what this is for. I would have thought more like
    sql = "Update Tracks set [Track] = 1." & [Track] & " Where tID= " & c - 1 That assumes c is a variable in your code and cannot be 0 or null.

    Then debug.print the sql as WGM suggested, copy it and see if it will run in a new query.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  9. #9
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    365
    I was debug.printing it and trying different things in the query designer. Eventually OK. Problem was the quotes and so many "&" chars.
    Code:
    sql = "UPDATE Tracks SET Track = " & Chr$(34) & "1." & Chr$(34) & " & [Track] WHERE (((tID)=" & c - 1 & "));"
    Thanks for the feedback.

  10. #10
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    So Track is not a numeric field?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    365
    Yes Track is Numeric. So why are quotes needed? No there way "." is there?

  12. #12
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    If Track is numeric field type, the apostrophe or quote delimiter should not be needed. They are used when field is text type.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  13. #13
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    365
    I couldn't make it work without the quotes. It would change the . into # and instead of 1.1, 1.2 it became 11 12.

  14. #14
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    I couldn't make it work without the quotes.
    Then the values can be considered numeric but the field data type must be text. Look at the table field in design view and see what it is.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  15. #15
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    if track is numeric, why not just add them together

    sql = "UPDATE Tracks SET Track = " & 1+([Track]/10) WHERE (((tID)=" & c - 1 & "));"

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 03-09-2022, 11:28 AM
  2. Replies: 6
    Last Post: 07-09-2021, 10:38 AM
  3. Replies: 2
    Last Post: 08-03-2017, 04:58 AM
  4. Replies: 7
    Last Post: 08-26-2013, 06:05 AM
  5. Replies: 2
    Last Post: 08-30-2012, 07:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums