Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1529
  • Last Modified:

ADO recordsource as Combo box rowsource

I am using the code below to populate the rowsource of a combo box as a value list in an Access .adp database, the only problem is that there is a char limit to the value list property of the combo box. I am wondering if there is any way in which I can point the ADO.recordset directly at the combo box's rowsource property.

Code:
Dim cnn As New ADODB.Connection, rs As New ADODB.Recordset, strSource As
String, strString As String, pword As String
'create an ADODB connection to a Access2000 database
 cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source= G:\IOS\Risk
Management\Risk Database\MFASRisk.mdb;"

'create an ADODB recordset using either pure sql or a query resident in the
remote Databse
 rs.Open "SELECT [*tblRisk].id, [*tblRisk].Title FROM [*tblRisk]", cnn, , ,
adCmdText

'set the record pointer to the first record in the recordset
        rs.MoveFirst
       
'create a loop to step through the open recordset until EOF is reached
  Do While Not rs.EOF
         'create a value list for the combo box
          strString = rs!id & "," & rs!Title
       
           rs.MoveNext
           strSource = strSource & strString & ";"
 Loop
 
'populate the combo box with the value list
    Combo0.RowSource = strSource


Many thanks,
Rob Tomey


0
rtomey
Asked:
rtomey
2 Solutions
 
nexusnationCommented:
what is wrong when you run the code? does something wrong happen?
0
 
PsychoDazeyCommented:
Why couldnt you just use:
Me.comboboxName.RowSource = RS after you open the connection to the recordset?  You would have to make sure you set the bound column property correctly so it displays the proper field from your query.  This code would have to be in the code behind your form, otherwise use:
Forms![FormName]!comboboxName.RowSource = RS
0
 
kraigCommented:
You could create a query and set the rowsource of the combo box to the query name (say 'qcboYourQuery').

Build the sql string the same way you are already, except use DBEngine(0)(0).QueryDefs("qcboYourQuery").SQL = strSource  in place of Combo0.RowSource = strSource.

You may need to requery the combo box (Me.Combo0.Requery).
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
pbleightonCommented:
kraig's suggestion will work, but you can cut out a step and just:
Combo0.RowSource = "SELECT [*tblRisk].id, [*tblRisk].Title FROM [*tblRisk]"

Just make sure you have established a link to the table in the remote DB.
0
 
1WilliamCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Accept question, split points to PsychoDazey ,kraig  and pbleighton
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
1William
EE Cleanup Volunteer
0
 
nexusnationCommented:
duh... stupid me :-)

That 'Points For' Q will sink very quickly... pbleighton is not active. just an idea, but could you raise it to 60 pts and split it 3 ways?
0
 
nexusnationCommented:
^
0
 
1WilliamCommented:
I rec. sticking with RotaredoM desicion, no points change.  based on the question, questioner propbably would of split that way too, sorry pbleighton
0
 
nexusnationCommented:
okie dokie...

i just realized that when i typed "duh... stupid me :-)", i thought that *I* was the CV, not you ;-)
0
 
nexusnationCommented:
pbleighton,

You have one 'Points For' question that you can claim.
Please see http://www.experts-exchange.com/Databases/MS_Access/Q_20709976.html

Thanks,
Andrew
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now