Link to home
Start Free TrialLog in
Avatar of rtomey
rtomey

asked on

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


Avatar of nexusnation
nexusnation
Flag of United States of America image

what is wrong when you run the code? does something wrong happen?
SOLUTION
Avatar of PsychoDazey
PsychoDazey

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pbleighton
pbleighton

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.
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
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?
I rec. sticking with RotaredoM desicion, no points change.  based on the question, questioner propbably would of split that way too, sorry pbleighton
okie dokie...

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

You have one 'Points For' question that you can claim.
Please see https://www.experts-exchange.com/questions/20709976/EXPERTS-CLAIM-YOUR-POINTS.html

Thanks,
Andrew