By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,498 Members | 835 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,498 IT Pros & Developers. It's quick & easy.

Determining Total # of Records and Absolute Position of Current Record on linked Subform

P: n/a
Access97

I hope someone out there can help. This is driving me crazy.
Basically, I am trying to recreate VBA's built in navigation feature
(The one that allows you to move first, next, previous, and last and
also tells you that you are on Record # or [Total # of Records]. The
navigation part was easy. My problem is determing the what record I
am on and the total number of records.

I put the following code into the my subforms on Current event:

'------------------------
dim RS_Temp as Recordset
set RS_Temp = me.recordsetclone

if not (rs.bof and rs.eof)then
me!txtAbsolutePosition = RS_Temp.AbsolutePosition + 1
RS_Temp.movelast
me!txtRecordCount = RS_Temp.RecordCount
end if
'-----------------------

The + 1 in the line "me!txtAbsolutePosition =
RS_Temp.AbsolutePosition + 1"
is because Absolute position is zero based.

The problem is that this code is never run because recordset clone
constantly returns an empty Recordset.

I have even tried putting the code in the MainForms on Current event,
also with no luck.

If I open the subform alone, the code seems to work fine. Does anyone
have a solution?

Thanks!!
Ryan
Nov 12 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On 15 Jan 2004 17:54:59 -0800 in comp.databases.ms-access,
ry************@kp.org (Ryan) wrote:
Access97

I hope someone out there can help. This is driving me crazy.
Basically, I am trying to recreate VBA's built in navigation feature
(The one that allows you to move first, next, previous, and last and
also tells you that you are on Record # or [Total # of Records]. The
navigation part was easy. My problem is determing the what record I
am on and the total number of records.

I put the following code into the my subforms on Current event:

'------------------------
dim RS_Temp as Recordset
set RS_Temp = me.recordsetclone

if not (rs.bof and rs.eof)then
me!txtAbsolutePosition = RS_Temp.AbsolutePosition + 1
RS_Temp.movelast
me!txtRecordCount = RS_Temp.RecordCount
end if
'-----------------------

The + 1 in the line "me!txtAbsolutePosition =
RS_Temp.AbsolutePosition + 1"
is because Absolute position is zero based.

The problem is that this code is never run because recordset clone
constantly returns an empty Recordset.

I have even tried putting the code in the MainForms on Current event,
also with no luck.

If I open the subform alone, the code seems to work fine. Does anyone
have a solution?


I generally set a textbox's (txtRecordNumber) controlsource to:

=RecordNumber("Item",Form)

Then in Form_Current()
txtRecordNumber.Requery

Then in a global module:

Function RecordNumber(pstrPreFix As String, pfrm As Form) As String
On Error GoTo RecordNumber_Err
Dim rst As DAO.Recordset
Dim lngNumRecords As Long
Dim lngCurrentRecord As Long
Dim strTmp As String

Set rst = pfrm.RecordsetClone
rst.MoveLast
rst.Bookmark = pfrm.Bookmark
lngNumRecords = rst.RecordCount
lngCurrentRecord = rst.AbsolutePosition + 1
strTmp = pstrPreFix & " " & lngCurrentRecord & " of " &
lngNumRecords

RecordNumber_Exit:
On Error Resume Next
RecordNumber = strTmp
rst.Close
Set rst = Nothing
Exit Function

RecordNumber_Err:
Select Case Err
Case 7951
strTmp = "No Record Source"
Case 3021
strTmp = "New " & pstrPreFix
Case Else
strTmp = "#" & Err.Number
MsgBox Err.Description, 16, "Error " & Err & " in
RecordNumber()"
End Select
Resume RecordNumber_Exit
Resume

End Function

--
A)bort, R)etry, I)nfluence with large hammer.
Nov 12 '05 #2

P: n/a
Me.txtCurrRec = Form.CurrentRecord
Me.txtTotalRecs = Form.RecordsetClone.RecordCount + IIf(Form.NewRecord, 1, 0)
Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.