locked
Moving items from one listbox to another. RRS feed

  • Question

  • I have two listboxes.

    Individual Tasks and Saved task.

    I have  a command button whose purpose is to move items from the indidvual tasks listbox to the Saved tasks listbox.

    I am however getting the following error. - The rowsourcetype property must be set to 'value list

     to use this method.

    and the debugger points to the following line - lsiSavedIndTasks.AddItem (Msg)

    Since i want to move data from the first listbox, i assumed the row source for the 2nd listbox had to be blank...


    Private Sub cmdAddTask_Click()
        Dim Msg As String
        Dim i As Variant
        
        If lstIndividualTasks.ListIndex = -1 Then
          Msg = "Nothing"
        
        Else
        
            For Each i In lstIndividualTasks.ItemsSelected
                Msg = "" & lstIndividualTasks.Column(1, i)
                lsiSavedIndTasks.AddItem (Msg)
            Next i
        End If
            
            
            
    End Sub

    Any help will be appreciated.


    olu Solaru

    Tuesday, July 2, 2019 6:39 PM

Answers

  • Could you show us the SQL for each list box.

    After you click on the cmdAddTask control you should requery the list boxes.

    something like

    Me.lstIndividualTasks.Requery

    Me.lsiSavedIndTasks.Requery


    If this post answered or helped you find the answer to your question, please mark it as such for other Forum users knowledge.


    • Edited by DriveEV Wednesday, July 3, 2019 1:59 PM
    • Marked as answer by osolaru71 Wednesday, July 3, 2019 9:27 PM
    Wednesday, July 3, 2019 1:55 PM

All replies

  • I haven't checked your code, but the error is telling you that the listbox your are trying to work with needs to have it's 'Row Source Type' property, from the Data tab on the Property Sheet, set to 'Value List' (it's probably currently set to 'Table/Query').

    Daniel Pineault, 2010-2018 Microsoft MVP
    Professional Support: http://www.cardaconsultants.com
    MS Access Tips and Code Samples: http://www.devhut.net

    Tuesday, July 2, 2019 7:16 PM
  • Are your list box using queries as row source?


    If this post answered or helped you find the answer to your question, please mark it as such for other Forum users knowledge.


    • Edited by DriveEV Tuesday, July 2, 2019 7:23 PM
    Tuesday, July 2, 2019 7:17 PM
  • Yes The listbox i that i am grabbing items from is using a Query as it's rowsource. I am sensing that this might be my issue.  totally overlooked it..

    olu Solaru

    Wednesday, July 3, 2019 12:23 PM
  • I am no longer getting that error, but nothing happens when I click on the command button.

    olu Solaru

    Wednesday, July 3, 2019 12:36 PM
  • Could you show us the SQL for each list box.

    After you click on the cmdAddTask control you should requery the list boxes.

    something like

    Me.lstIndividualTasks.Requery

    Me.lsiSavedIndTasks.Requery


    If this post answered or helped you find the answer to your question, please mark it as such for other Forum users knowledge.


    • Edited by DriveEV Wednesday, July 3, 2019 1:59 PM
    • Marked as answer by osolaru71 Wednesday, July 3, 2019 9:27 PM
    Wednesday, July 3, 2019 1:55 PM
  • This is the SQL for the first list box.  i assumed the 2nd listbox won't have any sql because that was where i was moving the items too.

    SELECT qryIndividualTasks.Training_Tasks.Task
    FROM qryIndividualTasks
    ORDER BY qryIndividualTasks.[Training_Tasks].[Task];


    olu Solaru

    Wednesday, July 3, 2019 2:12 PM
  • So it works now, i just need the listbox to refresh..  Will this be added to the click event or the event of the form

    olu Solaru

    Wednesday, July 3, 2019 4:44 PM