Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    DaveT99 is offline Advanced Beginner
    Windows 11 Access 2019
    Join Date
    Mar 2018
    Location
    SPAIN
    Posts
    94

    How to update numbers in a string based on a position number

    I have a table of 8 digit numbers
    I would like to update the last 2 digits to "00"
    and would then copy to a new field and then update digit positions 5 & 6 to "00"



    Foolishly I tried ??????00

    can anyone help
    many Regards

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,555
    Left(YourField,6) & "00"
    Why are you updating 5 & 6 to 0, when you said last 2 digits of an 8 digit field?

    If you are also changing 5 and 6, then just adjust the values above.

    Create a query with the adjusted values as an extra column to check.
    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

  3. #3
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,930
    if it is a number you can use

    ?(12345478\100)*100
    12345400

    and similarly for your next stage
    ?(12345400 \10000)*10000
    12340000

  4. #4
    DaveT99 is offline Advanced Beginner
    Windows 11 Access 2019
    Join Date
    Mar 2018
    Location
    SPAIN
    Posts
    94
    Thanks trying to do, unsuccessfull so far ha ha

    But thanks for the second tip

    You are so helpfull

  5. #5
    DaveT99 is offline Advanced Beginner
    Windows 11 Access 2019
    Join Date
    Mar 2018
    Location
    SPAIN
    Posts
    94
    My field name is L3 and am Struggling here I have tried to change just the last character i.e. Left(L3,8) & "0" without success

    do I paste this code into SQL or in the query view and do I use an update query?????

    Sorry for my ignorance

    will try the 2nd solution now; they are all numeric values

  6. #6
    DaveT99 is offline Advanced Beginner
    Windows 11 Access 2019
    Join Date
    Mar 2018
    Location
    SPAIN
    Posts
    94
    Hi CJ
    have tried without success, do I paste the above code in SQL view or Design View

    Sorry
    Dave

  7. #7
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    To actually update the values you would use an update query and have the expressions given to you in the UpdateTo row in query design.
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  8. #8
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,930
    My field name is L3 and am Struggling here I have tried to change just the last character i.e. Left(L3,8) & "0" without success
    well if there are only 8 character then all you are doing is appending a 0.

    Also 'without success' does not help us to help you. What does 'without success' mean?

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,555
    Quote Originally Posted by DaveT99 View Post
    My field name is L3 and am Struggling here I have tried to change just the last character i.e. Left(L3,8) & "0" without success

    do I paste this code into SQL or in the query view and do I use an update query?????

    Sorry for my ignorance

    will try the 2nd solution now; they are all numeric values
    Look up the syntax for the Left() function, as for an 8 digit field Left(L3,8) & "0" is nonsense. That just makes a 9 digit field.
    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

  10. #10
    DaveT99 is offline Advanced Beginner
    Windows 11 Access 2019
    Join Date
    Mar 2018
    Location
    SPAIN
    Posts
    94
    Quote Originally Posted by Gicu View Post
    To actually update the values you would use an update query and have the expressions given to you in the UpdateTo row in query design.
    Cheers,
    Thanks Vlad, did try that but will retry as it did update the last 2 digits but lost the first 6 characters

    Dave

  11. #11
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    That is why you try it first as a calculated field in a select query to view it side by side with the original field and if happy with what you see then you take the expression and use it in the update.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  12. #12
    DaveT99 is offline Advanced Beginner
    Windows 11 Access 2019
    Join Date
    Mar 2018
    Location
    SPAIN
    Posts
    94
    Quote Originally Posted by Gicu View Post
    That is why you try it first as a calculated field in a select query to view it side by side with the original field and if happy with what you see then you take the expression and use it in the update.

    Cheers,
    Thanks everyone for all you messages, especially CJ where he said what does without success mean!!!

    Here is a pdf that shows the original data, the update query and the result of running the query

    what am I doing wrong???

    Regards
    dave
    Attached Files Attached Files

  13. #13
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,555
    You have Left("L3",6)& "00
    You are using L3 as a literal, literally the word L3, not the field L3

    Look at my syntax. Replace YourField with L3. No quotes are required except for the 00
    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

  14. #14
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    and would then copy to a new field and then update digit positions 5 & 6 to "00"
    Where? Maybe I could figure that out on my own but I'd rather not have to download, unzip and poke around in your file to try to figure that out.

    If it's an 8 digit field and you update digits 7 and 8 to 00 and then digits 5 and 6 to 00 then why not just change the last four to 0000 in either the new field or the existing one? Then it can just be myField = (myField\1000)*1000 as CJ indicated. NOTE: you must use \ and not /.

    Left() is a string function and I don't see that working if your field is actually numeric. I think that function can only return a string, so you will likely get a data type mismatch error if you try to use it.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  15. #15
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,555
    In fact, as you are doing it to all the records, you could say it is calculated, and leave the original data well alone?
    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

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

Similar Threads

  1. Replies: 8
    Last Post: 07-17-2022, 08:48 AM
  2. Replies: 4
    Last Post: 02-01-2019, 12:41 AM
  3. Replies: 2
    Last Post: 08-16-2018, 06:56 AM
  4. Character Replacement by Position in String
    By J Bhujanga in forum Queries
    Replies: 5
    Last Post: 07-08-2017, 05:16 PM
  5. Replies: 5
    Last Post: 08-25-2014, 05:33 PM

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