Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems With list box

Status
Not open for further replies.

mo2783

Programmer
Nov 16, 2003
68
GB
Hi

I have the follwoing code which should populate a 2 Column listbox

Code:
Private Sub Form_Open(Cancel As Integer)

    strSQL = "SELECT tbl_Computer_Main_Applications.Computer_Main_Application_ID, tbl_Computer_Main_Applications.Computer_Main_App_Name, tbl_Computer_Main_Applications.Computer_Main_App_Version " & _
    "FROM tbl_Computer_Main_Applications;"
    
    Set rsOpened = OpenTable(strSQL)
    
    
    rsOpened.MoveFirst
    i = 0
    With Me.lstAppAvailable
        .Clear
        Do
                    
            .AddItem
        
            'Add the Item to the Listbox
            .list(i, 0) = rsOpened.Fields("Computer_Main_Application_ID")
            .list(i, 1) = rsOpened.Fields("Computer_Main_App_Name") & " " & rsOpened.Fields("Computer_Main_App_Version")

        

            i = i + 1
            rsOpened.MoveNext
        Loop Until rsOpened.EOF
    End With
   
    rsOpened.Close
    
End Sub

I get the following error "Compile error. method or data member not found" on .clear statement in the code.

Any idea whats wrong with the code?

The list box is created in MS Access 2003.

Regards

Mo
 
Remou

I tried RemoveItem i get error "Argument not optional" if i delete RemoveItem then i get the same error on line which reads .AddItem

am i not setting up a reference to something?

thanks

Mo
 
That is not a method of a Acess Listbox in 2003. You can look in the object browser for all properties and methods. May exist in 2007. MSform controls and Access form controls are different. I believe that works in VB.

make a custom procedure to iterate the list and use the remove item method.

Note. In fact the AddItem/removeItem method did not exist in Access until 2003.
 
Look at the object browser for add and remove item. You are using them incorrectly. These methods use an argument.
 
Thinking about it i dont really need to Remove items from list box as it populated when empty or do i?

But how do i populate a multi Column list box in Access 2003?

Is the code above any good?

Mo
 
You can use AddItem if you wish, but I prefer to set thhe RowSource to a table or query:


Code:
"SELECT tbl_Computer_Main_Applications.Computer_Main_Application_ID, tbl_Computer_Main_Applications.Computer_Main_App_Name, tbl_Computer_Main_Applications.Computer_Main_App_Version " & _
    "FROM tbl_Computer_Main_Applications;"

Me.lstAppAvailable.RowSource=strSQL

Or just set the rowsource in design view.
 
Anyway, use the Load event instead of the Open when you play with controls ...

The workaround for the lack of .Clear method:
.RowSource = ""

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks for the Help everyone. I have it working with SQL, but what if i was going to populate the listbox with "values" (Row Source Type as Value) via code, how would i populate the listbox with 2 columns?


Mo
 
You can use semi-colons in the English versions of Access:

RowSource: 1; Here; 2; There

You must ensure that the column count is set to 2.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top