Results 1 to 3 of 3
  1. #1
    Bcanfield83 is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    May 2018
    Posts
    81

    Question Insert multiple values from unbound Text Box into table


    Hi All,

    I'm trying to figure out how to take a list of values in an unbound Text Box (on a form), and insert those values into a specified table upon clicking a button.

    1) User pastes a list of names into the Text Box (txtNames) on the form. Each subsequent name is on a new line, e.g.:
    User1
    User2
    User3
    User4
    etc.
    2) Clicks Button
    3) Insert those names into tblUser_Listing; this table contains only a single text field called "Username"

    The current solution that I have is inserting the entire list of names into a single record in that table. E.g.: if I paste a list of 10 names into the Text Box and then click the button, it's inserting all 10 names into a single record in the table rather than 10 separate records.

    Code:
    CurrentDb.Execute "Insert Into tblUser_Listing (Username) " & _
                      "Values ('" & Me.txtNames & "')"
    Any help would be appreciated. Thanks!

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    The only way you can do this reliably is if the formatting of your input is identical each and every time.

    For instance if you have

    'joe blow patty t smith'

    and you were to separate names by a space this would look like 2.5 names rather than 2 names, one with a middle initial.

    If you reliably have a first and last name and *only* a first and last name you can load the string into an array then cycle through the array appending one record at a time into your target table.

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Depending on your circumstances, you could paste the data into a text file, then import the text file using a "format validation" routine to ensure names are of consistent format (as rpeare stated) and insert same into your table. Records where the format is different than expected, thn you could reject that record forr further analysis/activity.
    I would advise you to use 2 fields FirstName and LastName and not a single field.

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

Similar Threads

  1. Replies: 3
    Last Post: 06-12-2019, 12:20 PM
  2. Replies: 19
    Last Post: 09-09-2014, 01:36 AM
  3. Replies: 4
    Last Post: 08-01-2014, 09:20 AM
  4. Replies: 2
    Last Post: 05-01-2014, 01:28 PM
  5. How to Insert an unbound Form into table
    By fekrinejat in forum Forms
    Replies: 4
    Last Post: 02-04-2013, 10:34 PM

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