简体   繁体   中英

424 Error Access 2010 - Multiselect Listbox

I'm trying to create VBA code for multiselect listbox in Access 2010- so that when the user clicks on the command button, the program inputs the selection(s) into an array and then for each selection the user made (each "true" value), prints out the name of the selection (which in this case is a topic) and any items that are linked to that selection. I have two tables: Topics and Items. Each item is linked to up to three topics in the Topic table.

My problem is I keep on getting "Runtime error 424 Object Required". I simplified the code considerably so that I can narrow down the source of the current problem. The code I'm currently working with is:

Private Sub Command1_Click()

Dim I As Integer

For I = 0 To TopicsL.ListCount-1
     If TopicsL.Selected(I) Then
     Debug.Print “Hello”
 End If
Next I
End Sub

TopicsL is my listbox's name. The error seems to be in the following line: For I = 0 To TopicsL.ListCount-1

Do I need to modify the "TopicsL.ListCount" further?

Thank you for your time.

指定列表框的完整路径,例如form1.TopicsL.ListCount - 1

Are you sure you have named/spelt the Listbox correctly? To make sure you are referencing the correct listbox, use Me. When you type Me. then all the contols, properties, methods available to the Form will be listed, and when you start typing "top" it will lsit the ListBox name. If it did not, now you know there is some problem. If it did, make sure that the properties of the ListBox are set right.

Private Sub Command1_Click()
    Dim iCtr As Integer
    For iCtr = 0 To Me.TopicsL.ListCount - 1
        If Me.TopicsL.Selected(iCtr) Then _
            Debug.Print "Hello World !!"
    Next
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM