A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Populate a combo box



 
 
Thread Tools Display Modes
  #1  
Old June 4th, 2004, 10:26 AM
Dilani
external usenet poster
 
Posts: n/a
Default Populate a combo box

How do you populate a combo box with results from a SQL query that is saved in a recordset?
Eg.
Set rstResult = db.OpenRecordset(strSQL)
' Loop the Recorset and fill the combo box
Do While Not rstResult.EOF
' what goes here?
rstResult.MoveNext
Loop
rstResult.Close

Thanks
Dilani
  #2  
Old June 4th, 2004, 11:11 AM
Gerald Stanley
external usenet poster
 
Posts: n/a
Default Populate a combo box

When populating a combo box in this manner you have to
build the rowSource as a string value with the RowSource
with the RowSourceType = 'Value List'.
For a single column dropdown list, the code would be along
the lines of

Set rstResult = db.OpenRecordset(strSQL)
' Loop the Recorset and fill the combo box
strRowSource = ""
Do While Not rstResult.EOF
strRowSource = strRowSource & rstResult!column & ";"
rstResult.MoveNext
Loop
rstResult.Close
comboBox.RowSource = Left(strRowSource,
Len(strRowSource)-1)

Hope This Helps
Gerald Stanley MCSD
-----Original Message-----
How do you populate a combo box with results from a SQL

query that is saved in a recordset?
Eg.
Set rstResult = db.OpenRecordset(strSQL)
' Loop the Recorset and fill the combo box
Do While Not rstResult.EOF
' what goes here?
rstResult.MoveNext
Loop
rstResult.Close

Thanks
Dilani
.

  #3  
Old June 4th, 2004, 11:51 AM
Dilani
external usenet poster
 
Posts: n/a
Default Populate a combo box

Thanks for the help.

Is there any other way of doing it? Because when I have a long result in the recordset, I get a run time error 2176. It says the Characters for this property is too long needs to be 255 or 2048.

Any other suggestions?

Thanks
Dilani


----- Gerald Stanley wrote: -----

When populating a combo box in this manner you have to
build the rowSource as a string value with the RowSource
with the RowSourceType = 'Value List'.
For a single column dropdown list, the code would be along
the lines of

Set rstResult = db.OpenRecordset(strSQL)
' Loop the Recorset and fill the combo box
strRowSource = ""
Do While Not rstResult.EOF
strRowSource = strRowSource & rstResult!column & ";"
rstResult.MoveNext
Loop
rstResult.Close
comboBox.RowSource = Left(strRowSource,
Len(strRowSource)-1)

Hope This Helps
Gerald Stanley MCSD
-----Original Message-----
How do you populate a combo box with results from a SQL

query that is saved in a recordset?
Eg.
Set rstResult = db.OpenRecordset(strSQL)
' Loop the Recorset and fill the combo box
Do While Not rstResult.EOF
' what goes here?
rstResult.MoveNext
Loop
rstResult.Close
Thanks

Dilani
.

  #4  
Old June 4th, 2004, 01:30 PM
Kevin Sprinkel
external usenet poster
 
Posts: n/a
Default Populate a combo box

Sure. Simply set the Combo Box' Row Source to the SQL
statement, e.g.,

SELECT YourTable.Field1, YourTable.Field2 FROM YourTable
ORDER BY YourTable.Field1;

HTH
Kevin Sprinkel

-----Original Message-----
How do you populate a combo box with results from a SQL

query that is saved in a recordset?
Eg.
Set rstResult = db.OpenRecordset(strSQL)
' Loop the Recorset and fill the combo box
Do While Not rstResult.EOF
' what goes here?
rstResult.MoveNext
Loop
rstResult.Close

Thanks
Dilani
.

  #5  
Old June 4th, 2004, 03:50 PM
Gerald Stanley
external usenet poster
 
Posts: n/a
Default Populate a combo box

Not really. There is no AddItem method with the combo box
in Access. The 'normal' mode is to use a SQL statement as
the RowSource. The Value List alternative is usually for
short lists only.

Gerald Stanley MCSD
-----Original Message-----
Thanks for the help.

Is there any other way of doing it? Because when I have a

long result in the recordset, I get a run time error 2176.
It says the Characters for this property is too long needs
to be 255 or 2048.

Any other suggestions?

Thanks
Dilani


----- Gerald Stanley wrote: -----

When populating a combo box in this manner you have to
build the rowSource as a string value with the RowSource
with the RowSourceType = 'Value List'.
For a single column dropdown list, the code would be

along
the lines of

Set rstResult = db.OpenRecordset(strSQL)
' Loop the Recorset and fill the combo box
strRowSource = ""
Do While Not rstResult.EOF
strRowSource = strRowSource &

rstResult!column & ";"
rstResult.MoveNext
Loop
rstResult.Close
comboBox.RowSource = Left(strRowSource,
Len(strRowSource)-1)

Hope This Helps
Gerald Stanley MCSD
-----Original Message-----
How do you populate a combo box with results from a SQL

query that is saved in a recordset?
Eg.
Set rstResult = db.OpenRecordset(strSQL)
' Loop the Recorset and fill the combo box
Do While Not rstResult.EOF
' what goes here?
rstResult.MoveNext
Loop
rstResult.Close
Thanks

Dilani
.

.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 02:30 PM.


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