Results 1 to 10 of 10
  1. #1
    jasbrown is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2013
    Posts
    5

    pbaldy - Multi-Select Listbox

    pbaldy - I stumbled across your "Use a Multi-Select Listbox to Add Records to a Table example". It is exactly what I wanted and I have incorporated it into my form. Thank you! However, in your example, after I click the submit button the controls do not refresh. The records are successfully inserted into the table but the form controls continue to display what I just typed/selected. I thought I could simply add the Me.Requery to the code but this does not resolve the problem. What do I need to do? http://www.baldyweb.com/MultiselectAppend.htm

  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,043
    You can do this type of thing to clear the listbox:

    Code:
      Dim x As Integer
      For x = 0 To ctl.ListCount - 1
        ctl.Selected(x) = False
      Next x
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    jasbrown is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2013
    Posts
    5
    Paul, thank you for the prompt response. I am afraid I need a little more detail. I copied your code snippet above and pasted it into the bottom of your Private Sub cmdAddRecords_Click() event within your sample MultiSelectAppend database. When I click the Add Records button, the employees that I selected are still highlighted and the value I entered for the Other Value field is still displayed.

  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,043
    Why don't you post your code, and we'll fix it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    jasbrown is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2013
    Posts
    5

    Here is what I currently have.

    Private Sub AssignTraining_Click()
    Dim strSQL As String
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim ctl As Control
    Dim varItem As Variant
    On Error GoTo ErrorHandler
    Set db = CurrentDb()
    Set rs = db.OpenRecordset("EmployReport", dbOpenDynaset, dbAppendOnly)
    'make sure a selection has been made
    If Me.TrainingID.ItemsSelected.Count = 0 Then
    MsgBox "Must select at least 1 training course"
    Exit Sub
    End If

    'add selected value(s) to table
    Set ctl = Me.TrainingID
    For Each varItem In ctl.ItemsSelected
    rs.AddNew
    rs!TrainingID = ctl.ItemData(varItem)
    rs!EmployeeID = Me.EmployeeID
    rs!YearID = Me.YearID
    rs.Update
    Next varItem

    ExitHandler:
    Set rs = Nothing
    Set db = Nothing
    Exit Sub
    ErrorHandler:
    Select Case Err
    Case Else
    MsgBox Err.Description
    DoCmd.Hourglass False
    Resume ExitHandler
    End Select

    Dim x As Integer
    For x = 0 To ctl.ListCount - 1
    ctl.Selected(x) = False
    Next x

    End Sub

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,043
    You have it in the error handler. The Dim line should be at the top with the others, the rest right after

    Next varItem
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    jasbrown is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2013
    Posts
    5
    Paul, thank you! The TrainingID control is successfully returning to its original state of not having any selections. However, I still need the EmployeeID control and YearID control to requery so that they return to their original state of no selection.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,043
    You don't requery them, you set their value:

    Me.Whatever = Null
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    jasbrown is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2013
    Posts
    5
    Perfect! Thank you for all of your help.

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,043
    No problem, and welcome to the site by the way!
    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. Search using a multi select listbox
    By noobaccess in forum Access
    Replies: 13
    Last Post: 12-04-2012, 07:06 AM
  2. multi select listbox
    By crowegreg in forum Forms
    Replies: 3
    Last Post: 07-28-2012, 01:48 PM
  3. Looping through a multi select listbox - how do I do it?
    By shabbaranks in forum Programming
    Replies: 4
    Last Post: 04-02-2012, 11:56 AM
  4. Update Column from Multi-select listbox
    By jhargram in forum Forms
    Replies: 4
    Last Post: 02-27-2012, 12:03 PM
  5. Need Multi-Select listbox code example
    By Buakaw in forum Forms
    Replies: 4
    Last Post: 08-21-2011, 08:37 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