Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2002
    Location
    Wyoming
    Posts
    48

    Unanswered: "No current record." + Listbox

    Hello:

    I have a form with a listbox which is populated with a callback function. The callback function is being called by the OnClick event of a combo box. That event selects the records to populate the listbox and creates a recordset. This works fine; however, when I click on any item in the listbox I get the error message "No current record." This message is being returned by the callback function.

    I want to be able to click on a name in the listbox and have the appropriate record selected from the recordset and populate the form.

    Do I have to bookmark the record that is being selected?

    Thanks for your ideas and help.
    Cheers,
    Ken

  2. #2
    Join Date
    Nov 2002
    Location
    Wyoming
    Posts
    48
    Any ideas?
    Cheers,
    Ken

  3. #3
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    How did you setup this listbox? What are it's properties? How is it to function? (i.e. unbounded? bound to a table or query?)

  4. #4
    Join Date
    Nov 2002
    Location
    Wyoming
    Posts
    48
    Originally posted by M Owen
    How did you setup this listbox? What are it's properties? How is it to function? (i.e. unbounded? bound to a table or query?)
    The list box is bound to a function DocStatus. A user makes a selection from a combo box and based on that selection an SQL query is run and a recordset is built. Then the function DocStatus is called which populates an array from the data in the recordset and then the function fills the list box.

    I set the Bound Column property to column 1.

    All works fine until I click on a name in the list box, then the function returns "No Current Record." Hmmm...Maybe the data is not being preserved in the array?
    Cheers,
    Ken

  5. #5
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Originally posted by KennyG
    The list box is bound to a function DocStatus. A user makes a selection from a combo box and based on that selection an SQL query is run and a recordset is built. Then the function DocStatus is called which populates an array from the data in the recordset and then the function fills the list box.

    I set the Bound Column property to column 1.

    All works fine until I click on a name in the list box, then the function returns "No Current Record." Hmmm...Maybe the data is not being preserved in the array?
    Possible ... Let's see how you're doing it ...

  6. #6
    Join Date
    Nov 2002
    Location
    Wyoming
    Posts
    48
    Here is the code:

    Private Sub cmbGrade_Click()
    Dim bGradeID As Byte
    Dim sName As String

    'Declare recordsets
    Dim rstGrade As DAO.Recordset

    'Declare SQL Strings
    Dim sqlGrade As String


    Set dbGrade = CurrentDb()

    'Select grade ID from tbl_Grade
    sqlGrade = "SELECT tbl_Grade.GradeID " _
    & "FROM tbl_Grade " _
    & "WHERE tbl_Grade.Grade = '" & Me.cmbGrade & "'"
    Set rstGrade = dbGrade.OpenRecordset(sqlGrade, dbOpenDynaset, dbReadOnly)
    bGradeID = rstGrade!GradeID

    'Select students from tbl_students based on value of bGrade.
    sqlStudents = "SELECT * " _
    & "FROM tbl_Students " _
    & "WHERE tbl_Students.s_Grade = " & bGradeID & " " _
    & "ORDER BY s_LastName ASC"
    Set rstStudents = dbGrade.OpenRecordset(sqlStudents, dbOpenDynaset)

    If rstStudents.RecordCount = 0 Then
    MsgBox ("No students have been selected.")
    Else
    rstStudents.MoveLast
    rstStudents.MoveFirst
    lstStudent_Staff.RowSourceType = "DocStatus"
    End If

    Set rstGrade = Nothing

    End Sub

    Function to fill listbox:

    Public Function DocStatus(fld As Control, id As Variant, row As Variant, col As Variant, code As Variant) As Variant
    Dim ReturnVal As Variant
    Static intRow As Byte
    Static bytRecCount As Byte

    bytRecCount = rstStudents.RecordCount

    Const COLUMN_COUNT = 1

    On Error GoTo Fill_Error

    ReDim Preserve arrTest(0 To bytRecCount - 1, COLUMN_COUNT)

    Select Case code
    Case acLBInitialize ' Initialize.
    ReturnVal = True
    Case acLBOpen ' Open.
    ReturnVal = Timer ' Unique ID.
    Case acLBGetRowCount ' Get rows.
    ReturnVal = bytRecCount
    Case acLBGetColumnCount ' Get columns.
    ReturnVal = COLUMN_COUNT
    Case acLBGetColumnWidth ' Get column width.
    ReturnVal = -1 ' Use default width.
    Case acLBGetValue ' Get the data.
    arrTest(row, col) = rstStudents!s_LastName
    ReturnVal = arrTest(row, col)
    rstStudents.MoveNext
    End Select

    DocStatus = ReturnVal
    Exit Function

    Fill_Error:
    MsgBox ("Function DocStatus: " & Err.Description & " " & Err.Source)
    Exit Function

    End Function

    Code that gets executed when user makes selection from listbox

    Private Sub lstStudent_Staff_Click()
    Dim frm As Form
    Dim ctlSource As Control
    Dim ctlDest As Control
    Dim strItems As String
    Dim intCurrentRow As Integer

    Set frm = Forms!frm_StudentStaff
    Set ctl = frm!lstStudent_Staff
    For intCurrentRow = 0 To ctl.ListCount - 1
    If ctl.Selected(intCurrentRow) Then
    strItems = strItems & ctl.Column(0, intCurrentRow) & ";"
    End If
    Next intCurrentRow
    MsgBox (arrTest(1, 1))
    MsgBox (strItems)

    ' Reset destination control's RowSource property.
    ' ctlDest.RowSource = ""
    ' ctlDest.RowSource = strItems

    End Sub
    Cheers,
    Ken

Posting Permissions

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