Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Record Counter within a Subfrom

Posted on 2010-11-23
8
431 Views
Last Modified: 2012-05-10
Hello Experts,

I am chasing some code for a record counter within a subform as I have chosen NO for the Navigation Buttons witihin form properties. The subform links to the form via a field named IMI.

Ultimately, it would be great to show this in a text box next to the command buttons I now use as navigation buttons.

LK
0
Comment
Question by:lkirke
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 9

Expert Comment

by:Stephan_Schrandt
ID: 34203129
You can use the form_current event. Taken from http://www.databasedev.co.uk/navigation-record-count.html

Private Sub Form_Current()

' Provide a record counter for using with
' custom navigation buttons (when not using
' Access built in navigation)

    Dim rst As DAO.Recordset
    Dim lngCount As Long

    Set rst = Me.RecordsetClone

    With rst
        .MoveFirst
        .MoveLast
        lngCount = .RecordCount
    End With
   
'Show the result of the record count in the text box (txtRecordNo)

    Me.txtRecordNo = "Record " & Me.CurrentRecord & " of " & lngCount
       
End Sub
0
 
LVL 10

Expert Comment

by:conagraman
ID: 34205045

no code is needed.
you can put a text box in a subfom's "form Header" or "page header" with a control source of
=Count(a filed name)
i have attached a database for you to take a look at. in the sample i use the ID field so the control source for the text box is

=Count(ID)

: )

counter.accdb
0
 
LVL 11

Assisted Solution

by:LambertHeenan
LambertHeenan earned 100 total points
ID: 34205494
No need event to call the Count() routine.

Just an unbound text box (Call it "txtRecordInfo" for this discussion), and in the form's current event this one line...

txtRecordInfo = currentRecord & " of " & Me.RecordsetClone.RecordCount
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

Author Comment

by:lkirke
ID: 34227783
Hello Experts, tried some of the suggestions and tried to keep it fairly simple by not needing to call upon code or routines.

LambertHeenan: Unfortunately the code doesn't work.

However, I have attached an example where I get the record count of total records working, but am unsure as indicate the current record within the total number of records.

For example: 4 of 8, 5 of 8, 6 of 8 etc etc  Example.mdb
0
 
LVL 10

Accepted Solution

by:
conagraman earned 400 total points
ID: 34230016
the below code should do the trick. put it in the control source of the textbox just like you did with =count(NMI).
replace that code with this:

=[CurrentRecord] & " of " & Count([NMI])
0
 
LVL 11

Expert Comment

by:LambertHeenan
ID: 34230896
" Unfortunately the code doesn't work" are you sure you put the code in the sub form's Current event? This code certailing works for me. Is the form bound or not?
0
 
LVL 10

Expert Comment

by:conagraman
ID: 34230965
the code does work in the sample database he uploaded.
i suspect a control source was assigned and the code was used at the same time causing an error.
0
 

Author Closing Comment

by:lkirke
ID: 34236678
Thank you to all Experts. Works as requested.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question