VBA Excel populate CommandBox with values from SQL

  • Hi All,


    I have a combobox with 2 bound columns and below code to populate it:



    However it fails on .List(Num - 1, 0) = rsPubs![L.intLaptopID] with error "Item cannot be found in the collection corresponding to the requested name or ordinal."


    The sme querry runs fine when run in SQL Server Management Studio returning 1 column.


    Any help please?


    Thank you.

  • Re: VBA Excel populate CommandBox with values from SQL


    No Worries guys. I found the mistake. It was the SQL statement. Set the columns with AS and it worked.


    Cheers.

  • Re: VBA Excel populate CommandBox with values from SQL


    or maybe:

    Code
    with rs
        .Open "SELECT L.intLaptopID, L.strLaptopName from tblLaptops L, tblUser U, tblUserLaptop LU WHERE L.intLaptopID = LU.intLaptopID AND LU.intUserID = U.intUserID AND U.strUsername = '" & Me.txtReturnName.Value & "' " 
    	cbLoanLaptop.Column = .GetRows() 
        .Close 
    End With

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!