Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    tmg73 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2014
    Posts
    7

    Is there a way to replace the first 5 numbers in each cell with 9999?

    Hi there,
    Is there a macro or other shortcut to replace the first 5 numbers in a whole column of numbers with 99999? I've been doing this manually and it's a royal pain.



    Thanks!
    --Todd

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Run an "Update" query. Something like:
    Code:
    UPDATE YourTableName SET YourTableName.YourFieldName= "99999" & Mid("YourFieldName",5);
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    The expression needs one change :

    UPDATE YourTableName SET YourTableName.YourFieldName= "99999" & Mid("YourFieldName",6);

    Everything after column 5 starts in column 6.

    John

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Quote Originally Posted by John_G View Post
    The expression needs one change :

    UPDATE YourTableName SET YourTableName.YourFieldName= "99999" & Mid("YourFieldName",6);

    Everything after column 5 starts in column 6.

    John
    You are of course quite right about the "6", but I've just realized that the quote marks around the YourFieldName should actually be square brackets. So I think it should be:
    UPDATE YourTableName SET YourTableName.YourFieldName= "99999" & Mid([YourFieldName],6);
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    tmg73 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2014
    Posts
    7
    Quote Originally Posted by Bob Fitz View Post
    You are of course quite right about the "6", but I've just realized that the quote marks around the YourFieldName should actually be square brackets. So I think it should be:
    UPDATE YourTableName SET YourTableName.YourFieldName= "99999" & Mid([YourFieldName],6);
    OK, so how do I do this for an entire column of data?

  6. #6
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Quote Originally Posted by tmg73 View Post
    OK, so how do I do this for an entire column of data?
    Not sure what you mean. That will change the value in every row, or do you mean how do you replace all the digits rather than just the first 5.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  7. #7
    tmg73 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2014
    Posts
    7
    Quote Originally Posted by Bob Fitz View Post
    Not sure what you mean. That will change the value in every row, or do you mean how do you replace all the digits rather than just the first 5.
    No, just the first 5 digits.

    I apologize but I am a total Access newbie. I am trying to use the query design. I don't see anywhere to add a whole line of code like you are instructing.

    I have the query run to select the data, and now it is asking for "Update To:".

    Don't worry, I am trying this on a copy so I don't mess up the original..

  8. #8
    tmg73 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2014
    Posts
    7
    OK, I figured out I have to place "99999" & Mid([YourFieldName],6) in the Update To: box. It appears to work. Can I get it to ignore cells with nothing in them?

  9. #9
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Quote Originally Posted by tmg73 View Post
    No, just the first 5 digits.

    I apologize but I am a total Access newbie. I am trying to use the query design. I don't see anywhere to add a whole line of code like you are instructing.

    I have the query run to select the data, and now it is asking for "Update To:".

    Don't worry, I am trying this on a copy so I don't mess up the original..
    Said, we should have warned you about making a backup.
    Anyway, copy the posted code. open a new query in Design View. If you get a Dialog box open asking you which tables to add to the query, just close it, without selecting any tables. Once it has closed you should see a button on the toolbar with SQL on it. Click that then paste the code into the open pane. Then click the Run button on the toolbar. It looks like an exclamation mark.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  10. #10
    tmg73 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2014
    Posts
    7
    Quote Originally Posted by Bob Fitz View Post
    Said, we should have warned you about making a backup.
    Anyway, copy the posted code. open a new query in Design View. If you get a Dialog box open asking you which tables to add to the query, just close it, without selecting any tables. Once it has closed you should see a button on the toolbar with SQL on it. Click that then paste the code into the open pane. Then click the Run button on the toolbar. It looks like an exclamation mark.
    Hi, sorry, re-posting so you see this:

    OK, I figured out I have to place "99999" & Mid([YourFieldName],6) in the Update To: box. It appears to work. Can I get it to ignore cells with nothing in them?

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,948
    Filter the records to be updated:

    WHERE [YourFieldName] Not Is Null
    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.

  12. #12
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Quote Originally Posted by tmg73 View Post
    OK, I figured out I have to place "99999" & Mid([YourFieldName],6) in the Update To: box. It appears to work. Can I get it to ignore cells with nothing in them?
    Yes. Will look at that shortly. Just having dinner.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  13. #13
    tmg73 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2014
    Posts
    7
    OK, the "Is Not Null" goes into the "Criteria" parameter. Done!
    Thanks!!

  14. #14
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    ttng73

    Did you see June's post. That would go on the end of the code I posted, or you could change the query to Design View and put
    Not Is Null
    in the "Criteria" row.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  15. #15
    tmg73 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2014
    Posts
    7
    I did see it, thanks all!

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

Similar Threads

  1. Replies: 1
    Last Post: 07-12-2013, 01:48 PM
  2. Replies: 12
    Last Post: 01-15-2013, 02:35 PM
  3. Replies: 3
    Last Post: 06-07-2012, 07:05 AM
  4. Replies: 2
    Last Post: 11-29-2011, 05:26 PM
  5. Can we post Access cell data to Excel cell properties?
    By Zethro in forum Import/Export Data
    Replies: 1
    Last Post: 12-13-2005, 08:42 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