LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Populating a multi column listbox with ADO Recordset

Hello. I'm trying to populate a multicolumn listbox with a ADO recordest
from mdb. I came so far with code which works for 1 and 2 columns, but i cant
make it work for 3 columns. it keeps reporting Type mismatch .List =
Application.Transpose(pArray)

Code:
Private Sub ListBox1_Click()
'Option Explicit
'Set reference to the Microsoft ActiveX Data Objects x.x Library!

'Global constants required
Const glob_sdbPath = "C:\ifran.mdb"
Const glob_sConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
glob_sdbPath & ";"


Dim rcArray As Variant
Dim pArray As Variant
Dim cnt As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim pSQL As String
Dim sSQL As String
If ListBox1.ListIndex = 0 Then
'Set the location of your database, the connection string and the SQL query
sSQL = "SELECT Predmet, id_predmet FROM 192 ORDER BY predmet;"
pSQL = "SELECT program, smer, id_vsi FROM stari ORDER BY program, id_vsi;"


'Open connection to the database
cnt.Open glob_sConnect

'Open recordset and copy to an array
rst.Open sSQL, cnt
rcArray = rst.GetRows
rst.Close
rst.Open pSQL, cnt
pArray = rst.GetRows
Set rst = Nothing
With Me.ListBox4
.Clear
.ColumnCount = 3
.ColumnWidths = "150;150;30"
.List = Application.Transpose(pArray)
.ListIndex = -1
End With

'Place data in the listbox
With Me.ListBox5
.Clear
.ColumnCount = 2
.ColumnWidths = "310;30"
.List = Application.Transpose(rcArray)
.ListIndex = -1
End With

'Close ADO objects
cnt.Close
Set rst = Nothing
Set cnt = Nothing
ElseIf ListBox1.ListIndex = 1 Then
'Set the location of your database, the connection string and the SQL query
sSQL = "SELECT Predmet, id_predmet FROM 196 ORDER BY predmet;"
pSQL = "SELECT program, id_vsi FROM prenovljeni ORDER BY program, id_vsi;"


'Open connection to the database
cnt.Open glob_sConnect

'Open recordset and copy to an array
rst.Open sSQL, cnt
rcArray = rst.GetRows
rst.Close
rst.Open pSQL, cnt
pArray = rst.GetRows
Set rst = Nothing
With Me.ListBox4
.Clear
.ColumnCount = 3
.ColumnWidths = "310;30"
.List = Application.Transpose(pArray)
.ListIndex = -1
End With

'Place data in the listbox
With Me.ListBox5
.Clear
.ColumnCount = 2
.ColumnWidths = "310;30"
.List = Application.Transpose(rcArray)
.ListIndex = -1
End With

'Close ADO objects
cnt.Close
Set rst = Nothing
Set cnt = Nothing
ElseIf ListBox1.ListIndex = 2 Then
'Set the location of your database, the connection string and the SQL query
sSQL = "SELECT Predmet, id_predmet FROM 197 ORDER BY predmet;"
pSQL = "SELECT program, smer, id_vsi FROM znanstveni ORDER BY program, smer,
id_vsi;"

'Open connection to the database
cnt.Open glob_sConnect

'Open recordset and copy to an array
rst.Open sSQL, cnt
rcArray = rst.GetRows
rst.Close
rst.Open pSQL, cnt
pArray = rst.GetRows
With Me.ListBox4
.Clear
.BoundColumn = 3
.ColumnCount = 3
.ColumnWidths = "150;150;30"
.List = Application.Transpose(pArray)
.ListIndex = -1
End With
'Place data in the listbox
With Me.ListBox5
.Clear
.ColumnCount = 3
.ColumnWidths = "310;30"
.List = Application.Transpose(rcArray)
.ListIndex = -1
End With

'Close ADO objects
rst.Close
cnt.Close
Set rst = Nothing
Set cnt = Nothing
End If

End Sub
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Populating a multi column listbox with ADO Recordset Paul Faulkner Excel Programming 2 September 16th 05 07:10 PM
filling a two column listbox from a two column recordset Dennis Excel Programming 5 May 23rd 04 10:13 PM
How to populate a multi-column activeX listbox on a spreadsheet with an ADO recordset quartz Excel Programming 1 May 3rd 04 10:13 PM
populating a multi-column Listbox Tom Ogilvy Excel Programming 3 April 26th 04 08:26 PM
populating a multi-column Listbox Harald Staff Excel Programming 1 April 26th 04 08:26 PM


All times are GMT +1. The time now is 08:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"