View Full Version : combox preload speed up
mshbhwn98
08-21-2014, 08:52 AM
Hi,
Im populating a combobox with the result from a stored procedure in SQL and it is taking a long time. It is due to the size of the result. the sp returns 154,000 rows. It only takes 1 second to run but the populating of the combobox takes much much longer. Is there a way I can speed this up? Here is my code (cbx is the combobox)
With cbx.Object
.Clear
Do
.AddItem Rst![Name]
Rst.MoveNext
Loop Until Rst.EOF
.ListIndex = 0
End With
Thanks
mshbhwn98
08-21-2014, 09:27 AM
I have found this code and looks useful...
'Example for adding items into combo by using Win32 API.
'
'Written by Nir Sofer
'Web site: http://nirsoft.mirrorz.com (http://nirsoft.mirrorz.com/)
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const CB_ADDSTRING = &H143
Private Const CB_SETITEMDATA = &H151
Private Sub cmdComboAPI_Click()
Dim strItemText As String
Dim lngIndex As Long
Dim dblTimer As Double
Dim lngAddIndex As Long
cmbTest.Clear
dblTimer = Timer
'Adding items strings and items data with Win32 API
For lngIndex = 1 To 5000
strItemText = "item number " & CStr(lngIndex)
'Add the new string to the ComboBox.
lngAddIndex = SendMessage(cmbTest.hWnd, CB_ADDSTRING, 0, ByVal strItemText)
'Set the item data of the new item.
SendMessage cmbTest.hWnd, CB_SETITEMDATA, lngAddIndex, ByVal lngIndex
Next
MsgBox Format(Timer - dblTimer, "0.000") & " seconds"
End Sub
I'm just trying to implement it but im quite new at this so might take a while. If anyone could guide me I'd appreciate it
Thanks
sub M_snb()
combobox1.Column=rst.getrows
End Sub
mshbhwn98
08-21-2014, 10:55 PM
Thank you so much. So simple.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.