Results 1 to 5 of 5
  1. #1
    Star Lounger
    Join Date
    Jan 2002
    Location
    London, Gtr London, England
    Posts
    63
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Callback functions lstboxes (2000)

    I am having troubles using a callback function to populate a combobox and list box. When I scroll through the combo box it errors due to end of recordset.

    I should say I populate the cbo/listbox with an adorecordset, looping through the row numbers.
    what do I need to do to eliminate this error?

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Callback functions lstboxes (2000)

    Without seeing your callback function, it's a bit difficult to guess at what the problem might be. If you post the code, someone should be able to help.

    For reference, I'm attaching a callback function using an ADO recordset. This is code I built some years ago, and it worked at the time.
    Charlotte

  3. #3
    Star Lounger
    Join Date
    Jan 2002
    Location
    London, Gtr London, England
    Posts
    63
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Callback functions lstboxes (2000)

    The following is my call back code.

    Option Compare Database
    Public pp_rstAdo As Recordset

    Public Function CallBack(ctlCurrent As Control, varID As Variant, varRow As Variant, _
    varColumn As Variant, varCode As Variant) As Variant
    Dim varReturn As Variant
    Dim strSQL As String
    Dim cnnADO As Connection



    Select Case varCode
    'Initialise
    Case acLBInitialize
    strSQL = "SELECT ProductHierarchy_Ref, MARSDivision " & _
    "FROM tblDivision " & _
    "ORDER BY ProductHierarchy_Ref"

    Set cnnADO = New ADODB.Connection
    Set pp_rstAdo = New ADODB.Recordset

    If OpenADOConnection_FilePath(cnnADO, g_strDBPICKCAL_PROVIDER, CurrentDb.Name) Then
    If OpenADORecordset_SQL(pp_rstAdo, strSQL, cnnADO, adUseClient, adOpenForwardOnly, adLockReadOnly) Then
    varReturn = True
    Else
    varReturn = True
    End If
    Else
    varReturn = True
    End If

    'Open
    Case acLBOpen
    varReturn = Timer 'Generate unique ID for Control

    'Get row count
    Case acLBGetRowCount
    varReturn = pp_rstAdo.RecordCount

    'get number of columns
    Case acLBGetColumnCount
    varReturn = 2

    'get column width
    Case acLBGetColumnWidth
    varReturn = -1 'use defaults

    'Populate the control
    Case acLBGetValue
    If Not pp_rstAdo.BOF And Not pp_rstAdo.EOF Then
    Select Case varColumn
    Case 0
    If varRow = 0 Then
    'do nothing this is the heading row
    Else
    varReturn = pp_rstAdo.Fields(0).Value
    End If
    Case 1
    If varRow = 0 Then
    'do nothing this is the heading row
    Else
    varReturn = pp_rstAdo.Fields(1).Value
    End If
    End Select
    pp_rstAdo.MoveNext
    End If
    Case acLBEnd
    CloseADORecordset pp_rstAdo
    CloseADOConnection cnnADO
    End Select
    CallBack = varReturn
    End Function

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Callback functions lstboxes (2000)

    Your code for the acLBGetValue case isn't valid - each time the list is fetched, you move to the next record - again and again and again. Instead of this, you must loop through the records in the acLBInitialize case, and populate an array. The acLBGetValue case just retrieves the appropriate array item. The code Charlotte attached shows how to do this.

    By the way, what is the purpose of all the Ifs in

    If OpenADOConnection_FilePath(cnnADO, g_strDBPICKCAL_PROVIDER, _
    CurrentDb.Name) Then
    If OpenADORecordset_SQL(pp_rstAdo, strSQL, cnnADO, adUseClient, _
    adOpenForwardOnly, adLockReadOnly) Then
    varReturn = True
    Else
    varReturn = True
    End If
    Else
    varReturn = True
    End If
    Whatever the situation, you always set varReturn = True. <img src=/S/scratch.gif border=0 alt=scratch width=25 height=29>

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Callback functions lstboxes (2000)

    Where in the code does the error occur and what specific error message are you getting? Is it in the callback or in the AfterUpdate of the combobox. For that matter, have you checked the several custom functions in the callback to see if your error is in them? I'm referring to OpenADOConnection_FilePath, OpenADORecordset_SQL, CloseADORecordset and CloseADOConnection? If you get the error scrolling through the list, it doesn't sound like the callback is the problem, since that has already populated the list.
    Charlotte

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •