Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default This one's more serious

I need help with this syntax... I have been able to successfully load my
ComboBox from a SQL Server Recordset. However, I am only getting one column
in my combo box, and I need both columns from the recordset to show. Can one
of you masters show me what is wrong with my code, or how to tweak it to make
the combo box load both columns of my query.

'Set Up cmbxCustomerSelection
With cmbxCustomerSelection
.ColumnCount = 2
.BoundColumn = 2
.TextColumn = 1
End With

'Load cmbxCustomerSelection
Do While Not adoRsA.EOF
cmbxCustomerSelection.AddItem adoRsA(0).Value
adoRsA.movenext
Loop


Much appreciation!
DBAL

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 575
Default This one's more serious

DBAL,

Try this:

Do While Not adoRsA.EOF
cmbxCustomerSelection.AddItem adoRsA(0).Value
cmbxCustomerSelection.List(cmbxCustomerSelection.L istCount - 1,1) =
adoRsA(1).Value
adoRsA.movenext
Loop

Robin Hammond
www.enhanceddatasystems.com

"DBAL" wrote in message
...
I need help with this syntax... I have been able to successfully load my
ComboBox from a SQL Server Recordset. However, I am only getting one
column
in my combo box, and I need both columns from the recordset to show. Can
one
of you masters show me what is wrong with my code, or how to tweak it to
make
the combo box load both columns of my query.

'Set Up cmbxCustomerSelection
With cmbxCustomerSelection
.ColumnCount = 2
.BoundColumn = 2
.TextColumn = 1
End With

'Load cmbxCustomerSelection
Do While Not adoRsA.EOF
cmbxCustomerSelection.AddItem adoRsA(0).Value
adoRsA.movenext
Loop


Much appreciation!
DBAL



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 318
Default This one's more serious

Robin has already shown you one way. This is another way. Here you first
store all the values in an array (from a recordset) and then use them to fill
the list box all at once.

Sub test()

Dim a2DimArray(1 To 4, 1 To 2) As String
a2DimArray(1, 1) = "a1"
a2DimArray(2, 1) = "a2"
a2DimArray(3, 1) = "a3"
a2DimArray(4, 1) = "a4"
a2DimArray(1, 2) = "b1"
a2DimArray(2, 2) = "b2"
a2DimArray(3, 2) = "b3"
a2DimArray(4, 2) = "b4"

With Sheet1
.ListBox1.List = a2DimArray
End With
End Sub


Alok Joshi

"DBAL" wrote:

I need help with this syntax... I have been able to successfully load my
ComboBox from a SQL Server Recordset. However, I am only getting one column
in my combo box, and I need both columns from the recordset to show. Can one
of you masters show me what is wrong with my code, or how to tweak it to make
the combo box load both columns of my query.

'Set Up cmbxCustomerSelection
With cmbxCustomerSelection
.ColumnCount = 2
.BoundColumn = 2
.TextColumn = 1
End With

'Load cmbxCustomerSelection
Do While Not adoRsA.EOF
cmbxCustomerSelection.AddItem adoRsA(0).Value
adoRsA.movenext
Loop


Much appreciation!
DBAL

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default This one's more serious

Very nice Robin. I'll give this a try. Thanks alot!
DBAL.

"Robin Hammond" wrote:

DBAL,

Try this:

Do While Not adoRsA.EOF
cmbxCustomerSelection.AddItem adoRsA(0).Value
cmbxCustomerSelection.List(cmbxCustomerSelection.L istCount - 1,1) =
adoRsA(1).Value
adoRsA.movenext
Loop

Robin Hammond
www.enhanceddatasystems.com

"DBAL" wrote in message
...
I need help with this syntax... I have been able to successfully load my
ComboBox from a SQL Server Recordset. However, I am only getting one
column
in my combo box, and I need both columns from the recordset to show. Can
one
of you masters show me what is wrong with my code, or how to tweak it to
make
the combo box load both columns of my query.

'Set Up cmbxCustomerSelection
With cmbxCustomerSelection
.ColumnCount = 2
.BoundColumn = 2
.TextColumn = 1
End With

'Load cmbxCustomerSelection
Do While Not adoRsA.EOF
cmbxCustomerSelection.AddItem adoRsA(0).Value
adoRsA.movenext
Loop


Much appreciation!
DBAL




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default This one's more serious

Ahh Alok, thanks again. I will keep this solution handy... I am going to try
the other way first. But I am wondering, if I had mulitple columns to work
with would the array method be the best one?

Either way, thanks!

DBAL.

"Alok" wrote:

Robin has already shown you one way. This is another way. Here you first
store all the values in an array (from a recordset) and then use them to fill
the list box all at once.

Sub test()

Dim a2DimArray(1 To 4, 1 To 2) As String
a2DimArray(1, 1) = "a1"
a2DimArray(2, 1) = "a2"
a2DimArray(3, 1) = "a3"
a2DimArray(4, 1) = "a4"
a2DimArray(1, 2) = "b1"
a2DimArray(2, 2) = "b2"
a2DimArray(3, 2) = "b3"
a2DimArray(4, 2) = "b4"

With Sheet1
.ListBox1.List = a2DimArray
End With
End Sub


Alok Joshi

"DBAL" wrote:

I need help with this syntax... I have been able to successfully load my
ComboBox from a SQL Server Recordset. However, I am only getting one column
in my combo box, and I need both columns from the recordset to show. Can one
of you masters show me what is wrong with my code, or how to tweak it to make
the combo box load both columns of my query.

'Set Up cmbxCustomerSelection
With cmbxCustomerSelection
.ColumnCount = 2
.BoundColumn = 2
.TextColumn = 1
End With

'Load cmbxCustomerSelection
Do While Not adoRsA.EOF
cmbxCustomerSelection.AddItem adoRsA(0).Value
adoRsA.movenext
Loop


Much appreciation!
DBAL

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
Pivot Tables are showing One's where real value should be Rookie_User Excel Discussion (Misc queries) 3 July 25th 07 07:09 PM
Can AutoSave's default settings be changed to one's preference? SoNearRedmondICouldThrowWaterBombsAtThem Excel Discussion (Misc queries) 3 August 18th 06 11:42 PM
Match, Copy, Merge, Delete and Repeat... MVP's this one's for you. dannyfromnj Excel Discussion (Misc queries) 1 June 19th 06 10:14 PM
Pleeze Help! Export Excel data into a form in a Word Doc...this one's tough! duugg Excel Discussion (Misc queries) 1 April 21st 06 02:35 PM
can one write one's own Excel Function? Elliott Baral Excel Programming 2 September 29th 03 08:02 PM


All times are GMT +1. The time now is 04:18 AM.

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

About Us

"It's about Microsoft Excel"