|
Subject:
|
Loading data from SQL
|
|
Posted By:
|
levinll
|
Post Date:
|
1/25/2007 3:09:44 PM
|
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] " Else If IsMissing(WeekOf) = True Then SSQL = "EXEC [BuildActivityList] '" & Company & "'" Else SSQL = "EXEC [BuildActivityList] '" & Company & "','" & WeekOf & "'" End If End If With rc .ActiveConnection = cnStandByPay .CursorLocation = adUseServer .Source = SSQL .Open End With If rc.EOF = True Then BuildAccountDropDownList = "" Else Do While rc.EOF = False BuildAccountDropDownList = BuildAccountDropDownList & rc![Activity] & vbTab & Trim(rc![Description]) & "|" rc.MoveNext Loop End If rc.Close 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]" With rsLawsonActivityCodes .CursorType = adOpenStatic .LockType = adLockReadOnly .CursorLocation = adUseClient .Open SSQL, cnStandByPay End With 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.
Thanks!
|
|