I have been experimenting wiht using the Listbox Callback function to solve an issue I have with my db tool. The function below connects ADO to a SQL server database and table and reads those members of the table that fit the criteria and then fills in two columns in my listbox.
So far, it appears to init well, filling the array properly. What I am having a problem with is the control calls with the code acLBGetColumnWi dth (5) three times. the first two are correct, getting the sizes of the two columns, but then it calls a third time, with a -1 row and a 0 column and then crashes telling me I have an error, "Fill_Provider_ List may not be a valid setting....." yada yada.
Any ideas?
So far, it appears to init well, filling the array properly. What I am having a problem with is the control calls with the code acLBGetColumnWi dth (5) three times. the first two are correct, getting the sizes of the two columns, but then it calls a third time, with a -1 row and a 0 column and then crashes telling me I have an error, "Fill_Provider_ List may not be a valid setting....." yada yada.
Any ideas?
Code:
Function Fill_Assigned_Provider_List(fld As Control, ID As Variant, row As Variant, col As Variant, code As Variant) As Variant Static Provider_Assigned_List() As Variant Static RowCount As Integer Const TWIPS = 1440 Select Case code Case acLBInitialize ' Initialize. DW_Connect rs_Provider.CursorLocation = adUseServer StrSQL = "Select * from dim.Provider where InactivationDate is null;" rs_Provider.Open StrSQL, DWConn, adOpenKeyset, adLockOptimistic, adCmdText ReDim Preserve Provider_Assigned_List(rs_Provider.RecordCount, 1) As Variant Fill_Assigned_Provider_List = True rs_Provider.MoveLast rs_Provider.MoveFirst fCount = 0 For chkitm = 0 To rs_Provider.RecordCount - 1 If Not IsNull(rs_Provider.Fields("ServiceSection")) And Not IsNull(rs_Provider.Fields("ProviderSID")) Then fCount = fCount + 1 Provider_Assigned_List(fCount, 0) = rs_Provider.Fields("ProviderSID") Provider_Assigned_List(fCount, 1) = rs_Provider.Fields("StaffName") End If rs_Provider.MoveNext Next chkitm RowCount = fCount Case acLBOpen ' Open. Fill_Assigned_Provider_List = Timer Case acLBGetFormat Fill_Assigned_Provider_List = -1 Case acLBGetRowCount ' Get number of rows. Fill_Assigned_Provider_List = RowCount Case acLBGetColumnCount ' Get number of columns. Fill_Assigned_Provider_List = 2 Case acLBGetColumnWidth ' Column width. Select Case col Case 0: Fill_Assigned_Provider_List = 1 Case 1: Fill_Assigned_Provider_List = 3 * TWIPS End Select Case acLBGetValue ' Get data. If row > 0 Then Fill_Assigned_Provider_List = Provider_Assigned_List(row + 1, col) End If Case acLBEnd rs_Provider.Close DWConn.Close ' End. End Select End Function
Comment