Display record x out of y on button?

vent

Registered User.
Local time
Today, 04:50
Joined
May 5, 2017
Messages
160
Hi everyone

Just out of curiosity, is it possible to program a button to display record count (e.g. 1 of 5)? I know this can be done on the form, but maybe just to save a user an extra step, would this be feasible? I should mention though that this form displays information for different companies, and a lot of companies have different secondary associations. So one company record can have multiple associations. Is there a way either on the button or a label on the form to display the record count of the associations attached (Not the number of companies)?
 
Last edited:
Yes, a Recordset exposes two properties you need to do this: 1) AbsolutePosition, and 2) RecordCount. Note that RecordCount is not guaranteed to be accurate until you navigate the entire recordset, so consider code like...
Code:
Function GetPositionString(rst As dao.Recordset) As String
   With rst.Clone
      If Not .EOF Then .MoveLast
      GetPositionString = "Record " & rst.AbsolutePosition + 1 & " of " & .RecordCount
   End With
End Function
See how that navigates to the end of a clone in order to get an accurate RecordCount?
hth
Mark
 
And to display the information on the button, use Mark's code in the calling procedure, eg

forms!YourFormName!YourButtonName.caption = GetPositionString(YourRst)
 
Hi guys, thanks for your replies. Just to be sure, does Mark's code go on the button's on_click property? Over top of the embedded macro? Thanks
 

Users who are viewing this thread

Back
Top Bottom