?
Solved

ADO recordsource as Combo box rowsource

Posted on 2003-02-27
12
Medium Priority
?
1,485 Views
Last Modified: 2008-02-01
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
Comment
Question by:rtomey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 Comments
 
LVL 12

Expert Comment

by:nexusnation
ID: 8036504
what is wrong when you run the code? does something wrong happen?
0
 
LVL 6

Assisted Solution

by:PsychoDazey
PsychoDazey earned 100 total points
ID: 8036557
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
 
LVL 2

Accepted Solution

by:
kraig earned 100 total points
ID: 8036675
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
Industry Leaders: 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!

 
LVL 2

Expert Comment

by:pbleighton
ID: 8037057
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
 
LVL 18

Expert Comment

by:1William
ID: 8773875
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
 
LVL 12

Expert Comment

by:nexusnation
ID: 8859335
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
 
LVL 12

Expert Comment

by:nexusnation
ID: 8954701
^
0
 
LVL 18

Expert Comment

by:1William
ID: 8954796
I rec. sticking with RotaredoM desicion, no points change.  based on the question, questioner propbably would of split that way too, sorry pbleighton
0
 
LVL 12

Expert Comment

by:nexusnation
ID: 8954815
okie dokie...

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

Expert Comment

by:nexusnation
ID: 9149681
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question