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

    Aggregate comma separated list from textbox into table

    I have a form with a large text box where a user can paste in product_ids separated by commas(like so: 2455225,235234,455622,2352352,2352324). The form also figures out the sysdate (ie: "1/12/2014") and user id (ie: "34") in the background (not visible). Sysdate is in a textbox called "txtSysdate" and the user ID is in a text box called "txtUserId". I have a button on the bottom of the form "cmdSend" that needs execute VBA that will write this data to a table called "Request". I need to come up with a VBA that will take each comma separated value and pair it with the sysdate and user id from the text box and write it to a table called "Request". Any help would be greatly appreciated!

    Request_Table



    Product_Id User_Id Created_Date
    2455225 34 4/16/2014
    235234 34 4/16/2014
    455622 34 4/16/2014
    2352352 34 4/16/2014
    2352324 34 4/16/2014

  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,970
    Open a recordset in VBA, loop through the records, parse the string, write records to table. Like:

    Dim rs As DAO.Recordset, Dim aryID As Variant
    Set rs = CurrentDb.OpenRecordset("SELECT * FROM tablename;")
    rs.MoveFirst
    While Not rs.EOF
    aryID = Split(rs!ProductID)
    For i = 0 to UBound(aryID) - 1
    CurrentDb.Execute "INSERT INTO Results(Product_ID, User_ID, Created_Date) VALUES('" & ary(i) & "', " & UserID & ", #" & Date() & "#")
    Next
    rs.MoveNext
    Wend

    Or alternate code for the inner loop.

    For i = 0 to UBound(aryID) - 1
    rs.AddNew
    rs!Product_ID = ary(i)
    rs!User_ID = UserID
    rs!Created_Date = Date
    rs.Update
    Next
    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. Replies: 8
    Last Post: 06-04-2014, 10:41 AM
  2. exporting query to text comma separated
    By Pasi in forum Queries
    Replies: 6
    Last Post: 12-27-2013, 06:42 PM
  3. Replies: 8
    Last Post: 11-21-2013, 11:28 AM
  4. Replies: 2
    Last Post: 04-07-2011, 10:15 AM
  5. Replies: 1
    Last Post: 07-31-2009, 03:57 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