Results 1 to 4 of 4
  1. #1
    jmss96 is offline Novice
    Windows XP Access 2003
    Join Date
    Dec 2014
    Posts
    2

    Angry break a string into smaller bits

    Hello
    I am new to Access and new to this site. I have a problem I cannot find an answer to. Hoping I can get some help. I have a table imported from AS/400. This table has all kinds of information, but I am dealing with corrugated. I got it broke down to what I want except for one field. It is called SUPDS1 and it shows the following: (example 1) 58 x 60 Single wall sheet and (example 2) 18 1/4 X 13 5/8 X 10 5/8 ECT44. I want to break these lines down to show length, width and height. Example 1 would be 58 (length) and 60 (width) with no height. Example 2 would be 18 1/4 (length) , 13 5/8 (width) and 10 5/8 (height). In both examples, I am not worried about the wording, just the sizes. Also the numbers change because of the differences in case sizes. I did find the following online which worked for my length. Length: Left([SUPDS1], InStr([SUPDS1],"x")-1). If anyone could help me get width and height, it would be greatly appreciated.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    This will be difficult to do by expressions in query because of the inconsistent structure - not every value has height.

    I would use VBA procedure to extract the parts and save them into new fields in table. Something like:
    Code:
    Sub GetDims()
    Dim rs As DAO.Recordset
    Set rs = CurrentDb.OpenRecordset("SELECT SUPDS1, Length, Width, Height FROM table1;")
    Dim aData As Variant, i As Integer
    While Not rs.EOF
        rs.Edit
        aData = Split(rs!SUPDS1, "x")
        For i = 0 To UBound(aData)
            If InStr(aData(i), "/") Then
                rs.Fields(i + 1) = Trim(Left(aData(i), InStrRev(aData(i), "/") + 2))
            Else
                rs.Fields(i + 1) = Val(aData(i))
            End If
        Next
        rs.Update
        rs.MoveNext
    Wend
    End Sub
    Do you have to import this data regularly?
    Last edited by June7; 12-18-2014 at 01:35 AM.
    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
    jmss96 is offline Novice
    Windows XP Access 2003
    Join Date
    Dec 2014
    Posts
    2
    OK. I will try that, but where do I type all of that. Do I have to make a column in my table called Length , Width, Height or will it automatically be in my query table. I am just starting to work on this project so I am not sure how often I will need to import this data.

    Thanks

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Create the fields in table.

    The code would go in a VBA general module.

    Position cursor somewhere within the procedure and click Run from the VBA menu bar.

    Be sure to change the SQL statement for the recordset to use your table name.

    Might want to test with a copy of the table.
    Last edited by June7; 12-18-2014 at 02:07 PM.
    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.

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

Similar Threads

  1. Massive Data Bits Against Timeline of Events
    By Armorica in forum Database Design
    Replies: 1
    Last Post: 05-24-2013, 07:07 AM
  2. Replies: 42
    Last Post: 03-01-2013, 06:58 AM
  3. Replies: 2
    Last Post: 10-19-2012, 02:21 AM
  4. lost - linking date field based on a record with smaller Unique ID
    By stan.chernov@gmail.com in forum Queries
    Replies: 7
    Last Post: 09-16-2010, 02:22 PM
  5. File size smaller after saving
    By Pilotwings_64 in forum Access
    Replies: 1
    Last Post: 08-20-2010, 06:21 AM

Tags for this Thread

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