Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting the current record position on a form. 2

Status
Not open for further replies.
Jun 6, 2001
5
NZ
I have an access project where I need to get the current record position. Exactly like the record navigator.

I need it to display "Viewing 2 of 5" like the record bar at the bottom of the screen.

Basically I have lots of master detail forms and it needs to be part of the UI, but it is only for display.

I hope you understand what I mean.

I currently have an edit control recordsource like this:

="Viewing " & [Form].RecordSet.[AbsolutePosition] & " of " & Count(*) & " Systems"

But I get stupid stuff for the current position, like -1 of 10 etc..

Please help..

ZuluWarrior
 
Hi!

I solve it following:

I created text box for record navigation txtCurrentRecord and wrote codes:

Private Sub Form_Current()
Me.txtCurrentRecord = Me.CurrentRecord
end sub

Private Sub txtCurrentRecord_AfterUpdate()
On Error GoTo Err_txtCurrentRecord_AfterUpdate
Dim rst As Recordset
Dim lngRecordCount As Long
Dim lngCurrentRecord As Long

lngCurrentRecord = Me.CurrentRecord
Set rst = Me.RecordsetClone
lngRecordCount = rst.RecordCount

If Me.txtCurrentRecord <> Me.CurrentRecord Then
Select Case Me.txtCurrentRecord
Case Is <= 0
Me.txtCurrentRecord = 1
Case Is > lngRecordCount
If Me.NewRecord Then
Me.txtCurrentRecord = lngCurrentRecord
Else
Me.txtCurrentRecord = lngRecordCount
End If
End Select
If Me.txtCurrentRecord <> Me.CurrentRecord Then
DoCmd.GoToRecord , , acGoTo, Me.txtCurrentRecord
End If
End If
rst.Close
Set rst = Nothing

Exit_txtCurrentRecord_AfterUpdate:
Exit Sub

Err_txtCurrentRecord_AfterUpdate:
If Err.Number = 2105 Then 'You can't go to the specified record.You may be at the end of a recordset.
Resume Next
Else
MsgBox &quot;Error No &quot; & Err.Number & vbLf & Error$, , Me.Name & &quot; Sub txtCurrentRecord_AfterUpdate&quot;
Resume Exit_txtCurrentRecord_AfterUpdate
End If

End Sub

Aivars
 
I'm using this one

if IsNull(&quot;your primary key&quot;) = False then
Dim dk as new ADODB.Recordset
Set dk = me.RecordsetClone
dk.Bookmark = Me.Bookmark
fldRecordPosition = dk.AbsolutePosition & &quot;/&quot; & _
dk.RecordCount
End If

fldRecordPosition is a field on your form

regards Jurgen
 
I use an unbound text field with the data sources set as

=IIf(Count(*)<>0,&quot;Record&quot; & [CurrentRecord] & &quot; of &quot; & Count(*) & &quot;.&quot;,&quot;No Records Found&quot;)

Simple yet effective

Onya
WozFromOz
 
WozFromOz

I like simplicity! Is there a way to tie your record counter to a progress bar?

Jim DeGeorge [wavey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top