Results 1 to 4 of 4
  1. #1
    looloo is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    36

    Items in a List Box

    I want to run an update query on all records in a list box. My code kind of looks like this:



    Private Sub AssignButton_Click()
    Dim SQLMasterUpdate As String
    Dim oItem As Variant

    If Me!RestaurantListBox.ItemsSelected.Count <> 0 Then

    For Each oItem In Me!RestaurantListBox.ItemsSelected

    SQLMasterUpdate = "(This is the part I'm struggling with !)"
    DoCmd.RunSQL SQLMasterUpdate

    Next oItem

    Else
    MsgBox "Nothing was selected from the list", vbInformation
    Exit Sub 'Nothing was selected
    End If
    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    It would look something like:

    SQLMasterUpdate = "UPDATE TableName SET FieldName = Whatever WHERE KeyField = " & Me.RestaurantListBox.ItemData(oItem)

    In other words, you concatenate the value of the listbox into the SQL string.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    looloo is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    36
    Thank you! This forum is a life saver!

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. List in Report Shows All Items in Table, But I Only Want...
    By italianfinancier in forum Programming
    Replies: 1
    Last Post: 05-28-2011, 02:42 AM
  2. Select multiple items from list box
    By sharmaprashant22 in forum Queries
    Replies: 2
    Last Post: 05-05-2011, 12:18 PM
  3. Replies: 5
    Last Post: 04-04-2011, 09:57 AM
  4. Edit List Items
    By Broderhol in forum Forms
    Replies: 3
    Last Post: 02-23-2011, 05:51 PM
  5. list box items
    By thewabit in forum Forms
    Replies: 12
    Last Post: 01-01-2010, 08:59 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