Solved

Populate DBCombo at run time

Posted on 2004-04-02
9
361 Views
Last Modified: 2007-12-19
I have a simple form with a DBCombo that I want to populate from a field from and SQL database. I can make the connection ok, but can't get anything but the first record to add to the combo. Here is what I have so far.

Private Sub Form_Load()
Dim rs As ADODB.Recordset
Dim vSQL As String
Dim vUsers() As String
Dim x As Integer
    Set rs = New ADODB.Recordset
    GetServerFromReg 'Gets server connection info from registry *WORKING*
    Open_Conn 'This opens the connection *WORKING*
    vSQL = "SELECT pUser from tblMembers"
    rs.Open vSQL, intCon, adOpenStatic, adLockOptimistic, adCmdText
    Set cmbUser.DataSource = rs 'Seems to be working

'**This is where I think I am missing something unless I am totally on the wrong track.

    cmbUser.Refresh
End Sub
0
Comment
Question by:nacilep
[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
  • 6
  • 3
9 Comments
 
LVL 19

Accepted Solution

by:
Shauli earned 125 total points
ID: 10745523
Private Sub Form_Load()
Dim rs As ADODB.Recordset
Dim vSQL As String
Dim vUsers() As String
Dim x As Integer
    Set rs = New ADODB.Recordset
    GetServerFromReg 'Gets server connection info from registry *WORKING*
    Open_Conn 'This opens the connection *WORKING*
    vSQL = "SELECT pUser from tblMembers"
    rs.Open vSQL, intCon, adOpenStatic, adLockOptimistic, adCmdText
    With rs
        Do Until .EOF
            cmbUser.AddItem !pUser
            .MoveNext
        Loop
    End With
    rs.Close
End Sub

S
0
 

Author Comment

by:nacilep
ID: 10745541
That would work with a normal combobox, but the recordset is > 500 and that is extremely slow. I was hoping that using a data bound control would speed up the process.
0
 
LVL 19

Expert Comment

by:Shauli
ID: 10745560
The speed really depends on a) your connection, b) the aql statement. 500 or so sould be slow.

S
0
Independent Software Vendors: 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 19

Expert Comment

by:Shauli
ID: 10745562
Shouldn't be slow :)

S
0
 
LVL 19

Expert Comment

by:Shauli
ID: 10745591
btw, I assume that the major consuming time is opening the connection, and not loading the data to the combo.

S
0
 

Author Comment

by:nacilep
ID: 10745653
Opening the connection takes no time at all.

It is the loop for populating a normal combobox. I am trying to use a DBCombo which can't use the .AddItem method.

0
 
LVL 19

Expert Comment

by:Shauli
ID: 10745699
Well, the only way I know to have all records in the combo is to loop through the records.

S
0
 

Author Comment

by:nacilep
ID: 10748231
Well, this does seem to be the only answer I could find. I had it working that way before, but since I didn't clarify that, points awarded.

I'll ask another question on this, but when I do the combo update that way the form basically 'freezes' (I put a progress bar in to show the user how long is left). Is this easily fixable?
0
 
LVL 19

Expert Comment

by:Shauli
ID: 10748612
Yes, add DoEvents to the sub, as in:

 Private Sub Form_Load()
Dim rs As ADODB.Recordset
Dim vSQL As String
Dim vUsers() As String
Dim x As Integer

DoEvents '<<<<<<<<<<<<<<<<<<<<<<<<<<

    Set rs = New ADODB.Recordset
    GetServerFromReg 'Gets server connection info from registry *WORKING*
    Open_Conn 'This opens the connection *WORKING*
    vSQL = "SELECT pUser from tblMembers"
    rs.Open vSQL, intCon, adOpenStatic, adLockOptimistic, adCmdText
    With rs
        Do Until .EOF
            cmbUser.AddItem !pUser
            .MoveNext
        Loop
    End With
    rs.Close
End Sub

S
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

718 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