How to add more than 1 row in a combo box in VB?

L

Ling

I've a problem here:
I am using Microsoft Access and linked it to SQL server.
My code is as below:

note: cmbCustomerDetails is a combo box & type is a value
list

'Declaration
Dim cnn As ADODB.Connection
Dim cmd As ADODB.Command
Dim rst As ADODB.Recordset
Dim lngMove As Long

Set cnn = New ADODB.Connection
Set cmd = New ADODB.Command
Set rst = New ADODB.Recordset
rst.CursorType = adOpenStatic

'Open the connection
Set cnn = CurrentProject.Connection

'Set up the Command objects's Connection, SQL and
Parameter types
With cmd
.ActiveConnection = cnn
.CommandText = "SELECT tblDo.DoNumber AS [DO No],
tblDo.DoYear AS [Year], tblDo.DoDate FROM tblDo WHERE
tblDo.DoDate Between" & "#" & [Forms]![frmDeliveryOrder
(pop)]![txtstartYr] & "#" & "And" & "#" & [Forms]!
[frmDeliveryOrder (pop)]![txtendYr] & "#"

End With

Set rst = cmd.Execute
Me.cmbCustomerDetails.AddItem "DO No"
Do Until rst.EOF
Me.cmbCustomerDetails.AddItem Item:=(rst![DO No])

rst.MoveNext
Loop

cnn.Close
Set cnn = Nothing
Set cmd = Nothing

Currently, cmbCustomerDetails could not show rst![DO No].
I would like it to show Year, DoDate as well but how do I
do so?

Any ideas?

Thanx

Ling
 
N

Newbie

Here is how I do it . ..

Once the recordset has been created add the following code:

If rst.RecordCount > 0 Then
Me.cmbCustomerDetails.Value = ""
rst.MoveFirst
Do Until rst.EOF
strItem = rst.Fields("DO No")
Me.cmbCustomerDetails.AddItem item:=strItem
rst.MoveNext
Loop

HTH
Ali
 
G

Guest

Thanx.
But what about adding more than 1 column into the combo
box?

My query fetches the year n date as well..

Any ideas? Thanx

Ling
-----Original Message-----
Here is how I do it . ..

Once the recordset has been created add the following code:

If rst.RecordCount > 0 Then
Me.cmbCustomerDetails.Value = ""
rst.MoveFirst
Do Until rst.EOF
strItem = rst.Fields("DO No")
Me.cmbCustomerDetails.AddItem item:=strItem
rst.MoveNext
Loop

HTH
Ali

I've a problem here:
I am using Microsoft Access and linked it to SQL server.
My code is as below:

note: cmbCustomerDetails is a combo box & type is a value
list

'Declaration
Dim cnn As ADODB.Connection
Dim cmd As ADODB.Command
Dim rst As ADODB.Recordset
Dim lngMove As Long

Set cnn = New ADODB.Connection
Set cmd = New ADODB.Command
Set rst = New ADODB.Recordset
rst.CursorType = adOpenStatic

'Open the connection
Set cnn = CurrentProject.Connection

'Set up the Command objects's Connection, SQL and
Parameter types
With cmd
.ActiveConnection = cnn
.CommandText = "SELECT tblDo.DoNumber AS [DO No],
tblDo.DoYear AS [Year], tblDo.DoDate FROM tblDo WHERE
tblDo.DoDate Between" & "#" & [Forms]![frmDeliveryOrder
(pop)]![txtstartYr] & "#" & "And" & "#" & [Forms]!
[frmDeliveryOrder (pop)]![txtendYr] & "#"

End With

Set rst = cmd.Execute
Me.cmbCustomerDetails.AddItem "DO No"
Do Until rst.EOF
Me.cmbCustomerDetails.AddItem Item:=(rst![DO No])

rst.MoveNext
Loop

cnn.Close
Set cnn = Nothing
Set cmd = Nothing

Currently, cmbCustomerDetails could not show rst![DO No].
I would like it to show Year, DoDate as well but how do I
do so?

Any ideas?

Thanx

Ling


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top