Results 1 to 5 of 5
  1. #1
    LisaC is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2014
    Posts
    2

    Take One Column Of Excel Data And Split Into Multiple Rows Of MS Access Data

    I have data that is coming from Excel, (see attached example and also illustration of output needed in Access). I need to bring this data into my Access database however, once I get it in there, there are several things that I need to accomplish and don't know how to:
    For each size in the order field, the size data is separated by commas and the quantities are enclosed in parenthesis ie; Youth Large (1), Adult Small (1), Adult Medium (1),
    I need to separate this so that there is only one size in the field and then another field gets populated by the quantity data, copy the same data for that order ID to a new line and then insert the next size with it's corresponding quantity data. When the data has been split and there are no more sizes, it goes to the next record. I hope that I am explaining this correctly, please let me know if you need further info. The needed output is in the Excel file as a sample. Thanks so much for any help! LC
    Attached Files Attached Files

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I did not look at your attached file but, I use VBA to parse string variables and save the results to a table in cases like this.

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Save the excel book to a generic file say, \\server\myDataFile.xls
    Link this excel file to Access, called say, xlData2Import
    build a query that uses this table to append to an internal access table.
    build a query to give you the results.

    now everytime you you get a new file, save a copy to \server\myDataFile.xls
    run the import, run the results.

    As to the ORDER field, it should not be sent that way. It should be Qty, but if you cant change that, then after import there will need to be another query to 'parse' the English words in col H to actual QTY counts.

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Instead of an import query you will need a macro to call a parsing function. This fcn will append the data after parsing the order/size box

    Code:
    Public Function ParseOrders()
    Dim rst   'As Recordset
    Dim vOrderNo, vWord, vTxt
    Dim vQty, vSize
    Dim i As Integer
    Set rst = CurrentDb.OpenRecordset("xlData2Import")
    With rst
       While Not .EOF()
          vTxt = .Fields("Order").Value & ""
          vTxt = Replace(vTxt, ",", " ")
          vOrderNo = .Fields("Order#").Value & ""
          
          i = InStr(vTxt, ")")
          While i > 0 And Len(vTxt) > 0
                vWord = Left(vTxt, i - 1)
                vTxt = Mid(vTxt, i + 1)
                
                i = InStr(vWord, "(")
                vSize = Trim(Left(vWord, i - 1))
                vQty = Trim(Mid(vWord, i + 1))
          
               'Debug.Print vOrderNo, vSize, vQty
                  'add the parsed order to the order table
               sSql = "Insert into tOrders (ORDERNO,SIZE,QTY) VALUES ('" & vOrderNo & "','" & vSize & "'," & vQty & ")"
               DoCmd.RunSQL sSql
               i = InStr(vTxt, ")")
           Wend
           
          .MoveNext
      Wend
    End With
    Set rst = Nothing
    End Function

  5. #5
    LisaC is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2014
    Posts
    2
    thank you, I will try this

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

Similar Threads

  1. Text To Column problem while getting data from access in excel
    By scorpion99 in forum Import/Export Data
    Replies: 11
    Last Post: 01-06-2014, 04:28 PM
  2. Replies: 4
    Last Post: 12-19-2013, 01:18 PM
  3. Replies: 1
    Last Post: 07-01-2013, 08:21 AM
  4. Replies: 2
    Last Post: 06-06-2012, 01:04 PM
  5. Import to Excel from Access column of LOOKUP data type
    By Derek in forum Import/Export Data
    Replies: 1
    Last Post: 12-06-2010, 06:27 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