Results 1 to 7 of 7
  1. #1
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368

    INSERT INTO with listbox

    Hi all, question for you.



    I have a form that contains 3 comboboxes and a listbox. Let's call the values of those ComboA, ComboB, ComboC and List{1-3}.
    I want to turn the selection of those into a series of INSERT INTOs with List1 in the first, List2 in the second, and List3 in the third.

    Any help?

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    so the 3 items in the listbox are the 3 inserts? is it one value per record? or is it one value per field, with one record total?

    the best way is to loop the listbox values vertically, using listbox.columns(0, i), with i being the integer. concat values together with the rest of the sql string to get the final statement, then execute it with CURRENTDB.EXECUTE

  3. #3
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    the listbox is a multivalue listbox. lets say we want to assign students to a class. I have a combo box for a teacher, a combobox for a class, and a listbox of a bunch of students. The user selects a teacher, a class, and selects multiple students. each iteration of the students in the listbox would have to be its own insert into string.

  4. #4
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by TheShabz View Post
    the listbox is a multivalue listbox. lets say we want to assign students to a class. I have a combo box for a teacher, a combobox for a class, and a listbox of a bunch of students. The user selects a teacher, a class, and selects multiple students. each iteration of the students in the listbox would have to be its own insert into string.
    so basically what you'd have in a situation like that is something like:
    Code:
    dim s as string
    dim i as long
    
    for i=0 to me.listbox.rows.count-1
       if me.listbox.columns(0,i).selected then
          //EXECUTE sql with "me.listbox.columns(0,i)" as concated value
       end if
    next i
    I'm not an expert with listboxes Shabz, so you'll have to get the properties on your own, but that's the idea.

  5. #5
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    I think that will work. My hangup was on the .selected. I'll let you know tomorrow if it worked out. Thanks!

  6. #6
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    I was close. see here: http://msdn.microsoft.com/en-us/libr...ffice.11).aspx

    you need LISTCOUNT, not ROWS. sorry!

  7. #7
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    the syntax was a bit off but the logic worked. thanks!

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

Similar Threads

  1. INSERT query: insert new data only
    By drh in forum Access
    Replies: 2
    Last Post: 04-04-2014, 05:31 PM
  2. Horizontal listbox - ?
    By bane in forum Forms
    Replies: 3
    Last Post: 04-20-2010, 06:48 PM
  3. Replies: 3
    Last Post: 04-14-2010, 10:00 AM
  4. Listbox question
    By uaguy3005 in forum Access
    Replies: 1
    Last Post: 03-05-2010, 08:35 AM
  5. Columns in a Listbox
    By craigalaniz in forum Access
    Replies: 3
    Last Post: 01-07-2010, 01: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