Excel 2003
Hi,
I am using the following example code to load various combo-boxes on an excel form. The connection (co) is to an Access back-end database (Set co = New ADODB.Connection).
Each load may take a few seconds to perform. I have noticed that if I select a loaded/loading combo-box drop-down using the mouse, the speed of the load increases.
Is there any VBA code that I can add to assist the loading as I'd prefer that this is done 'behind the scenes' rather than
by USER intervention (I've tried applying SetFocus property on the combo-box but this doesn't appear to work). Any ideas?
Select combo-box to load and calling rotuine
Code:
genericFillDropDown "SELECT Id, ProductCode from qryProducts order by ProductCode", frmSetupBreederFeederInput.cmbCode01, False
Called loading routine
Code:
Public Sub genericFillDropDown(sqlString As String, ctrl As Control, allowBlank As Boolean)
'opens the SQl (which must be the bound column (index) and text
'will fail if wrong (GIGO)
Dim rs As New ADODB.Recordset
Dim fieldNo As Integer
Set rs = New ADODB.Recordset
rs.Open sqlString, co, adOpenForwardOnly, adCmdText
'not going to check that there are records as there MUST be
ctrl.Clear
If allowBlank Then
ctrl.AddItem 0
ctrl.Column(1, ctrl.ListCount - 1) = ""
End If
Do While Not (rs.EOF)
ctrl.AddItem rs(0)
For fieldNo = 1 To rs.Fields.count - 1
'ctrl.Column(fieldNo, ctrl.ListCount - 1) = blankForNull(rs(fieldNo))
ctrl.Column(fieldNo, ctrl.ListCount - 1) = rs(fieldNo)
DoEvents
Next
rs.MoveNext
Loop
If ctrl.ListCount <> 0 Then ctrl.ListIndex = 0
rs.Close
Set rs = Nothing
Set ctrl = Nothing
End Sub
Thanks in advance,