listbox??

miiia83

Board Regular
Joined
Feb 28, 2007
Messages
83
hi!

I was wondering if anyone could show me how the code to make a listbox.. The code I have in Excel VB is as shows... I want the function_code to be shown as a listbox!

Code:
Sub Get_Category()

    resrow = 3     'börjar vid cell 3,2
    rescol = 2
    Sheets("sheet1").Range("b2:j1000").ClearContents
    

    OpenConnection ("RFC")
   
    strQuery = "SELECT * FROM DESCRIPTIONS"   'DESCRIPTIONS = tabellnamn
    Set rs = ConnRFC.Execute(strQuery)
    Do Until rs.EOF
        Sheets("sheet1").Cells(resrow, rescol).Value = rs("FUNCTION_CODE")
        Sheets("sheet1").Cells(resrow, rescol + 1).Value = rs("DESCRIPTION")
        
        resrow = resrow + 1
        rs.MoveNext
    Loop
    
    KillConnection ("RFC")


End Sub
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Not sure...
Code:
Sub Get_Category()
    Dim a(), n As Long
    Sheets("sheet1").Range("b2:j1000").ClearContents
   
    OpenConnection ("RFC")
   
    strQuery = "SELECT * FROM DESCRIPTIONS"   'DESCRIPTIONS = tabellnamn
    Set rs = ConnRFC.Execute(strQuery)
    Do Until rs.EOF
        Sheets("sheet1").Cells(resrow, rescol).Value = rs("FUNCTION_CODE")
        Sheets("sheet1").Cells(resrow, rescol + 1).Value = rs("DESCRIPTION")
        n = n + 1 ReDim Preserve a(1 To 2, 1 To n)
        a(1,n) = rs("FUNCTION_CODE")
        a(2,n) = rs("DESCRIPTION")
        resrow = resrow + 1
        rs.MoveNext
    Loop
    
    KillConnection ("RFC")
    With ListBox1
        .ColumnCount = 2
        .ColumnWidth = "50;50"
        .Column = a
    End With
End Sub
 
Upvote 0
thanks for reply.. don't know know if it helped yet though...

n = n + 1 ReDim preserve a(1 to 2, 1 to n)

got an error.. expected end of statement??
 
Upvote 0
OOps

sorry that should be

n = n + 1 : ReDim Preserve a(1 To 2, 1 To n)

missing ":" in between
 
Upvote 0
Sorry for jumping in but we were having the same thread in international forum as well. http://www.mrexcel.com/board2/viewtopic.php?t=260026
I did however not provide any suggestions.

jindon said: Where do you have the ListBox?

I believe she does not have one. She wants it to be created automaticly.

Thanks fairwinds


milla83,

It is much much easier if you add ComboBox before you import the data from db.
 
Upvote 0
Yes exactly... don't have a listbox... is it not possible to create one with info from an access table??

If I have all the values in excel and then make a listbox out of them... i still have all the values written + them in a listbox...
I just want the listbox... Did that make sence? Kinda hard to explain in english

Mia
 
Upvote 0

Forum statistics

Threads
1,226,730
Messages
6,192,703
Members
453,748
Latest member
akhtarf3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top