Loading data from SQL
I am trying to find the fastest way to populate a combo box with data that's in a SQL Server DB.
I usually create a recordset and pass along a stored procedure as one of it's parameters to get the desired results(see below)
Set rc = New ADODB.Recordset
If IsMissing(Company) = True Then
SSQL = "EXEC [BuildActivityList] "
If IsMissing(WeekOf) = True Then
SSQL = "EXEC [BuildActivityList] '" & Company & "'"
SSQL = "EXEC [BuildActivityList] '" & Company & "','" & WeekOf & "'"
.ActiveConnection = cnStandByPay
.CursorLocation = adUseServer
.Source = SSQL
If rc.EOF = True Then
BuildAccountDropDownList = ""
Do While rc.EOF = False
BuildAccountDropDownList = BuildAccountDropDownList & rc![Activity] & vbTab & Trim(rc![Description]) & "|"
Set rc = Nothing
This works fine, but when the resulting recordset is big, it tends to slow down the displaying of the combo box.
I've also attempted to load all of the data as part of my start-up code(see code below), so I don't need to query the database, but using the .FIND method of a recordset is much slower than querying the database directly.
SSQL = "exec [BuildActivityList]"
.CursorType = adOpenStatic
.LockType = adLockReadOnly
.CursorLocation = adUseClient
.Open SSQL, cnStandByPay
rsLawsonActivityCodes.ActiveConnection = Nothing
I was wondering if there was a way to combine the two, so that I could create a secondary recordset based on the records I loaded at start-up, that would only have the records that I wanted to loop thru while populating the combo box.