Results 1 to 8 of 8
  1. #1
    MatthewR is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2015
    Posts
    118

    Open Form and Display Record Count

    I'm using a combo search box (named "Incident") to open a form (named "frmVictimInformation") that is filtered based on the combo box selection.

    If there are records found, I want the form to display the record count in a label (named "VictimRecordNumber") that says "Displaying Victim # X of X"

    However, even when there are multiple records, the label always says "Displaying Victim # 1 of 1"

    I've pasted my code below, with the problematic part in bold. Where did I go wrong? Thanks for your help. -Matthew

    Private Sub Command54_Click()
    Dim lngCount As Long
    lngCount = DCount("*", "[tblEventInformation]", "[Incident] =" & Me.Incident)
    If lngCount = 0 Then
    DoCmd.OpenForm "frmEventInformation", , , "Incident=" & Me.Incident.Value
    Forms![frmEventInformation]![Incident] = Me![Incident]
    Else


    DoCmd.OpenForm "frmEventInformation", , , "Incident=" & Me.Incident.Value
    DoCmd.GoToRecord acDataForm, "frmVictimInformation", acLast
    DoCmd.GoToRecord acDataForm, "frmVictimInformation", acFirst
    Form_frmVictimInformation.VictimRecordNumber.Capti on = "Displaying Victim # " & Form_frmVictimInformation.CurrentRecord & " of " & Form_frmVictimInformation.RecordsetClone.RecordCou nt
    End If
    End Sub

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Maybe something like this ...

    untested
    Code:
    Dim rs As DAO.Recordset
    Set rs = Me.RecordsetClone
    rs.MoveLast
    If rs.RecordCount > 0 Then
       MsgBox "There are " & rs.RecordCount & " records."
    Else
       MsgBox "No records match your criteria"
    End If

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You already have the number of incidents from the DCount function. Why are you using "Form_frmVictimInformation.RecordsetClone.RecordCo unt" to try and get the number of records?

    Do you expect the number of records reported by the DCount to be different from the "RecordsetClone.RecordCount" number???

    Try
    Code:
    Form_frmVictimInformation.VictimRecordNumber.Caption = "Displaying  Victim #  " & Form_frmVictimInformation.CurrentRecord & "  of  "  & lngCount
    Don't know what you will see using "Form_frmVictimInformation.CurrentRecord"....

  4. #4
    MatthewR is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2015
    Posts
    118
    Thanks very much, Steve. Unfortunately, though, I tried your code and it gave me the same problem. It still says "Displaying Victim # 1 of 1" on the form.

    In all honesty, I don't know the difference between DCount and RecordsetClone.RecordCount. I'm new to all this, so please pardon my ignorance!

    Please let me know if you have any other suggestions.

    Matthew

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Dcount is going to take a second trip to the data where RecordsetClone will not

  6. #6
    MatthewR is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2015
    Posts
    118
    Ok cool. As it happens, I just figured out a workaround. In the form's On Load event, I wrote the following:

    If Me.RecordsetClone.RecordCount <> 0 Then
    Me.RecordsetClone.MoveLast
    Me.VictimRecordNumber.Caption = "Displaying Victim # " & CurrentRecord & " of " & RecordsetClone.RecordCount
    End If

    That seems to do the trick. Out of curiosity, how would I use the DCount in this situation?

    Thanks again for your help. It is much appreciated!

    Matthew

  7. #7
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Out of curiosity, how would I use the DCount in this situation?
    Dim lngCount As Long
    lngCount = DCount("*", "[tblEventInformation]", "[Incident] =" & Me.Incident)

    If lngCount > 0 Then
    Me.VictimRecordNumber.Caption = "Displaying Victim # " & CurrentRecord & " of " & RecordsetClone.RecordCount
    else
    msgbox "No Records"
    DoCmd.Close acForm, Me.Name
    End If

    I would use RecordsetClone

    Code:
    Dim rs As DAO.Recordset
    Set rs = Me.RecordsetClone
    rs.MoveLast
    If rs.RecordCount > 0 Then
    Me.VictimRecordNumber.Caption = "Displaying Victim #  " & Me.CurrentRecord & "  of  " & rs.RecordCount
    Else
       MsgBox "No records match your criteria"
       DoCmd.Close acForm, Me.Name
    End If

  8. #8
    MatthewR is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2015
    Posts
    118
    Awesome, got it. Thanks very much.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 04-30-2013, 07:55 PM
  2. Report RecordSource record count at Open
    By GraeagleBill in forum Reports
    Replies: 11
    Last Post: 04-19-2013, 02:03 PM
  3. Replies: 1
    Last Post: 05-03-2012, 02:25 PM
  4. Display record count
    By jgelpi16 in forum Reports
    Replies: 5
    Last Post: 11-30-2010, 09:02 PM
  5. Replies: 1
    Last Post: 04-11-2010, 04:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums