Results 1 to 3 of 3
  1. #1

    Count of records in a query based form (Access 97/SR2)

    Another simple one I'm sure, but how can I check how many records will be displayed in a form that is based on a query?

    My form is based on a query that limits the records displayed to a client (the criteria is entered by the user in the query). I need to be able to check the total number of records so if no records are retrieved I can display a msgbox and then return the user to the menu.

    I successfully used a count in a macro that run on form activation but as soon as I started getting several results the count appeared to be too slow.

    Any help would be gratefully appreciated.

  2. #2
    3 Star Lounger
    Join Date
    Dec 2000
    Manassas, Virginia, USA
    Thanked 0 Times in 0 Posts

    Re: Count of records in a query based form (Access 97/SR2)

    Whenever I need to check a count and then display a message box I do so in code using dcount.
    If DCount("FieldNameToBeChecked", "QueryNameContainingFieldNameToBeChecked" < 1 Then
    MsgBox "There is no record for this person"
    Exit Sub
    Judy Jones, Computer Training Specialist
    Manassas, Virginia

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Sacramento, California, USA
    Thanked 1 Time in 1 Post

    Re: Count of records in a query based form (Access 97/SR2)

    Macros are not efficient for stuff like ths. Try this instead:

    <pre>Public Sub Form_Open(Cancel As Integer)
    Dim rst As DAO.Recordset
    Dim lngCount As Long

    Set rst = Me.RecordsetClone
    With rst
    If Not .EOF Then
    lngCount = .RecordCount
    End If 'Not .EOF
    End With 'rst
    If lngCount = 0 Then
    Cancel = True
    Msgbox "There are no records for this selection."
    End If 'lngCount = 0
    End Sub 'Form_Open(Cancel As Integer)</pre>


Posting Permissions

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