Results 1 to 9 of 9
  1. #1
    kmfdm is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    11

    Moving delimited data from one column to another

    Hello,

    How would you create a macro that would move delimited data from 'column1' to 'column2' in a table? Assuming the delimiter is a space.

    The only issue is that I want to move everything after the first space to 'column2' - even if there are multiple spaces after the first one.

    Is that easy to do?

    Thanks...

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    I don't use macros, but in a query or VBA code you could use the Mid() function along with the InStr() function to find the first space.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    kmfdm is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    11
    Thanks. Is there an example anywhere of how to do that with VBA in Access?

  4. #4
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    Not that I'm aware of. If you're trying to actually change the data in the table, simplest would be an update query. You can do it in VBA, with the Edit method within a recordset loop.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    At bottom of http://office.microsoft.com/en-us/ac...001135959.aspx you will find string manipulation functions.

    You probably want something like:

    Trim(Mid([fieldname], InStr([fieldname], " ")))

    The expression can be used on the Update To row of an Access UPDATE query.

    In a macro would probably use OpenQuery method to execute the saved Access query object.

    In VBA could be:
    CurrentDb.Execute "UPDATE tablename SET fieldname = Trim(Mid([fieldname], InStr([fieldname], ' ')))"

    If you want the edited data to save to another field and not alter the original data, reference the field names accordingly.
    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.

  6. #6
    kmfdm is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    11
    Thanks, June7...that SQL actually works well. It doen't seem to work correctly when I change the delimiter, though. using " - " for example:

    Trim(Mid([fieldname], InStr([fieldname], " - ")))

    It removes the first space and then leaves the "- " in front of the value in the second column. Do I need to change something?

  7. #7
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    InStr() returns the position of the first character, so add a couple:

    InStr(...) + 2
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    kmfdm is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    11
    perfect, thanks for your help. I'll make a macro to run the queries.

  9. #9
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    No problem.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Exporting data into delimited .txt
    By agenjo in forum Import/Export Data
    Replies: 3
    Last Post: 01-07-2013, 03:53 PM
  2. moving column data to rows
    By teasdam in forum Access
    Replies: 3
    Last Post: 12-23-2011, 08:39 AM
  3. Replies: 1
    Last Post: 12-08-2011, 08:03 AM
  4. create comma delimited string from column in query
    By younggunnaz69 in forum Queries
    Replies: 2
    Last Post: 04-30-2011, 04:26 PM
  5. Replies: 5
    Last Post: 09-10-2010, 10:07 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