Results 1 to 5 of 5
  1. #1
    Holly is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    2

    Separate Contents of a Field in a Query

    I have a field called sku. In a query I want to break this field (sku) into two separate pieces.


    A sku contains contents which describe both the color and size of a T-shirt. For example:

    See image below.

    I want to be able to sort everything that exists BEFORE the 4th hyphen and then also sort by everything AFTER the 4th hyphen. I only know how to do a Left(), Right(), or Mid() but since the number of characters vary in both the color and the size, I don’t think these will work.

    Any help will be greatly appreciated.
    Attached Thumbnails Attached Thumbnails Capture.JPG  

  2. #2
    jwhite is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Dec 2012
    Location
    North Carolina
    Posts
    349
    I'm not getting it. Seems to me if you just do an Ascending sort on SKU it would be in the order you want. If not, arrange the records below in the order you want and re-post it.
    Code:
    SKU Desc
    HI-PKT-LS-asphalt-2xlt = an asphalt colored shirt that is size 2XLT
    HI-PKT-LS-asphalt-lt = an asphalt colored shirt that is size
    HI-PKT-LS-asphalt-mt = an asphalt colored shirt that is size
    HI-PKT-LS-asphalt-st = an asphalt colored shirt that is size
    HI-PKT-LS-asphalt-xlt = an asphalt colored shirt that is size
    HI-PKT-LS-azalea-2xlt = an azalea colored shirt that is size
    HI-PKT-LS-azalea-lt = an azalea colored shirt that is size
    HI-PKT-LS-azalea-mt = an azalea colored shirt that is size
    HI-PKT-LS-azalea-st = an azalea colored shirt that is size
    HI-PKT-LS-azalea-xlt = an azalea colored shirt that is size

  3. #3
    jwhite is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Dec 2012
    Location
    North Carolina
    Posts
    349
    Looking at it again... The SKU shouldn't include the description of the item. You should have a Products table that has (amongst other fields) Style and Size. Style and Size would be a Foreign Key to tblStyles and tblSizes respectively. If you want to keep using "lt", "xlt" and "2xlt", then you will need to add a SortOrder field to tblSizes to get the order you want. With that, sorting would be very easy.

  4. #4
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Check out the instrrev function - does just what you want to do, i.e. looks for the first occurance of one string in another, but starting from the right to find it.

    for example: instrrev("aa-b-1234-fffff-34","-") yields 16, the position of the first hyphen from the right.

  5. #5
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051

    Separate Contents of a Field in a Query

    The split command


    Function splitskucokour (skutext as string) as text

    Dim skuarray(6)
    Skuarray =Split("skutext", "-")

    splitskucokour =Skuarray(4)

    End function

    The function can be called within a query

    A similar function splits a text field into smaller values in an array based on a separator (in this case a "-")

    Function splitskusize(skutext as string) as text

    Dim skuarray(6)
    Skuarray =Split("skutext", "-")

    splitskusize =Skuarray(5)

    End function

    Would get the size too all from same query


    Sent from my iPhone using Tapatalk

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

Similar Threads

  1. Table of Contents for 2 separate Reports
    By pharrison74 in forum Reports
    Replies: 70
    Last Post: 03-01-2016, 08:47 AM
  2. Replies: 9
    Last Post: 08-11-2014, 01:24 AM
  3. Replies: 5
    Last Post: 04-05-2014, 08:52 PM
  4. Replies: 3
    Last Post: 05-23-2011, 07:29 AM
  5. Replies: 0
    Last Post: 03-29-2011, 04:11 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