Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Populating a combobox by the getrows method


Hello,

with the following code I populate one combobox on a userform of
Excel.

Suppose to have a source table of N fields and M records, so the sub
would populate the combobox with M rows and N columns. What happens is
that if the recordset contains more than one record the combobox
populates correctly, the vadata variable gets bi-dimensional and I have
a list of M rows and N columns, like the source table. Viceversa, when
the recordset contains only one record, vadata gets monodimensional and
the combobox populates transposed of one column and N rows instead of
one row x N columns.

In the case of only one record I have tried to use the (.getrows)
statement, instead of application.transpose(.getrows) but the result is
the same. I have also tried to redim vadata preserving the data, but I
get a "index out of interval" error.

I know I could use other ways to populate the combobox, but I am
curious to understand why this one fails.

Thanks, Emiliano

'
' piece of code
'
stSQL = "SELECT Risorse.CID, Risorse.RepUtil, Risorse.ImpUtil,
Risorse.Profilo, " _
& "Risorse.Cognome, Risorse.Nome FROM Risorse WHERE
(((Risorse.Cessato) = True)) " _
& "ORDER BY Risorse.Cognome, Risorse.Nome;"

With cnt
CursorLocation = 3
Provider = "Microsoft.jet.OLEDB.4.0"
Properties("Data Source") = stDB
Properties("Jet OLEDB:Database Password") = PWORD
Open
'Instantiate the Recordsetobject and execute the SQL-state.
Set rst = .Execute(stSQL)
End With

With rst
MoveFirst 'To retrieve the Recordset.
'Set .ActiveConnection = Nothing 'Disconnect the recordset.
k = .Fields.Count

'Populate the array with the whole recordset.
vaData = Application.Transpose(.GetRows)

'statementes to populate the combobox
With Me.cbSelect
Clear
ColumnCount = k
BoundColumn = (k - 1)
List = vaData
ListIndex = -1
End With


--
eggpap

Excel 2003 on Vista HP System - can use VBA
------------------------------------------------------------------------
eggpap's Profile: http://www.thecodecage.com/forumz/member.php?userid=90
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=87598

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default Populating a combobox by the getrows method

Change .List to .Column ...
.Column = vaData
--
Jim Cone
Portland, Oregon USA


"eggpap"
wrote in message
Hello,
with the following code I populate one combobox on a userform of Excel.
Suppose to have a source table of N fields and M records, so the sub
would populate the combobox with M rows and N columns. What happens is
that if the recordset contains more than one record the combobox
populates correctly, the vadata variable gets bi-dimensional and I have
a list of M rows and N columns, like the source table. Viceversa, when
the recordset contains only one record, vadata gets monodimensional and
the combobox populates transposed of one column and N rows instead of
one row x N columns.

In the case of only one record I have tried to use the (.getrows)
statement, instead of application.transpose(.getrows) but the result is
the same. I have also tried to redim vadata preserving the data, but I
get a "index out of interval" error.

I know I could use other ways to populate the combobox, but I am
curious to understand why this one fails.

Thanks, Emiliano

'
' piece of code
'
stSQL = "SELECT Risorse.CID, Risorse.RepUtil, Risorse.ImpUtil,
Risorse.Profilo, " _
& "Risorse.Cognome, Risorse.Nome FROM Risorse WHERE
(((Risorse.Cessato) = True)) " _
& "ORDER BY Risorse.Cognome, Risorse.Nome;"

With cnt
CursorLocation = 3
Provider = "Microsoft.jet.OLEDB.4.0"
Properties("Data Source") = stDB
Properties("Jet OLEDB:Database Password") = PWORD
Open
'Instantiate the Recordsetobject and execute the SQL-state.
Set rst = .Execute(stSQL)
End With

With rst
MoveFirst 'To retrieve the Recordset.
'Set .ActiveConnection = Nothing 'Disconnect the recordset.
k = .Fields.Count

'Populate the array with the whole recordset.
vaData = Application.Transpose(.GetRows)

'statementes to populate the combobox
With Me.cbSelect
Clear
ColumnCount = k
BoundColumn = (k - 1)
List = vaData
ListIndex = -1
End With
--
eggpap
Excel 2003 on Vista HP System - can use VBA

Reply
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 combobox Scott J[_2_] Excel Programming 2 June 7th 07 10:07 PM
Populating Combobox WLMPilot Excel Programming 17 March 28th 07 03:07 AM
Populating a combobox WLMPilot Excel Programming 1 March 12th 07 08:07 PM
ComboBox populating problem Werner[_33_] Excel Programming 1 July 29th 05 10:00 PM
Populating a ComboBox DirInfo Excel Programming 1 March 17th 05 10:03 PM


All times are GMT +1. The time now is 06:46 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"