Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2002

    Unanswered: record count from combo box

    I'm creating a school database and on one form I want to be able to select a 'classid' (text value) from a combo box and have a text box next to it return the number of students, 'enrollmentid', in that class.

    I'm using a table called 'enrollment table' as the source of the form.

    The text box,'student count', used to return the count has:
    =DCount("[classid]","Enrollment details","[classid] = '" & Me.[class select] & "'")
    as its control source.

    When I select a class from the combo box, 'class select', I get a #name error message in the 'student count' text box.

    Any help would be greatly appreciated.

    BTW, 'enrollmentid' and 'classid' are both on the 'many' side of relationship, and are primary keys.

  2. #2
    Join Date
    Oct 2001
    Bay Area, CA
    Try to update your text box with the onchange event of your combo box:
    is 'class select' the name of your combo box??? And "Enrollment Table" or "Enrollment details" the table name??

    Private Sub classid_Change()
    Dim intCount As Integer
    intCount = DCount("[classid]", "Enrollment details", "[classid] = '" & Me.[class select] & "'")
    Me.[student count] = intCount
    End Sub

    Hope this helps...

  3. #3
    Join Date
    Jan 2002
    I took out the dcount code and placed your code as instructed.
    Works great!
    You're a life-saver.

Posting Permissions

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