thenelson,
I am looking for Boomark solution.
Thanks.
Main Topics
Browse All TopicsI need some help to complete the attached code. Depending on the value of the parameter supplied:
'iConst: 0 previous; 1 next; 2 first; 3 last; 5 new
It should show the record designated by iConst.
Thank you.
Function fnGoto(iConst As Integer)
Dim rs As DAO.Recordset
Dim i As Integer
Set rs = Me.RecordsetClone
With rs
' find the position of current record i
' update record no/ total records
Me!txtNoOfNos = i + 1 & "/" & .RecordCount
' use bookmark to navigate to the desired record identified by:
Select Case iConst
Case 0 'previous
go to the previous record
....
Case 1 'next
go to the first record
....
Case 2 'first
go to the first record
....
Case 3 'last
go to the last record
....
Case 5 'new
go to the new record
....
End Select
End With
rs.close
End Function
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
With bookmark:
Function fnGoto(iConst As Integer)
Dim rs As DAO.Recordset
Dim i As Integer
Set rs = Me.RecordsetClone
With rs
' find the position of current record i
' update record no/ total records
Me!txtNoOfNos = i + 1 & "/" & .RecordCount
' use bookmark to navigate to the desired record identified by:
Select Case iConst
Case 0 'previous
.MovePrevious
Case 1 'next
.MoveNext
Case 2 'first
.MoveFirst
Case 3 'last
.MoveLast
End Select
Me.Bookmark = .Bookmark
End With
rs.close
End Function
Without bookmark:
Function fnGoto(iConst As Integer)
Dim rs As DAO.Recordset
Dim i As Integer
Set rs = Me.Recordset 'Use the recordset itself instead of clone
With rs
' find the position of current record i
' update record no/ total records
Me!txtNoOfNos = i + 1 & "/" & .RecordCount
Select Case iConst
Case 0 'previous
.MovePrevious
Case 1 'next
.MoveNext
Case 2 'first
.MoveFirst
Case 3 'last
.MoveLast
End Select
End With
rs.close
End Function
So far I have the following. All works except add new record for which I will post a new question later:
Function fnGoto(iConst As Integer)
Dim rs As DAO.Recordset
Dim i As Integer
Dim BM As Variant
Dim iPosition As Long
Dim iEnable As Integer
Dim iTotal As Integer
Set rs = Me.RecordsetClone
With rs
rs.MoveFirst
Do Until rs.EOF
If !ID = Me!ID Then
iPosition = .AbsolutePosition
Exit Do
ElseIf Nz(Me!ID, "") = "" Then
.MoveLast
iPosition = .RecordCount
iEnable = -1
Exit Do
End If
.MoveNext
Loop
.MoveLast
iTotal = .RecordCount
.MoveFirst
Select Case iConst
Case 0: iPosition = iPosition - 1
Case 1: iPosition = iPosition + 1
Case 2: iPosition = 0
Case 3: iPosition = .RecordCount - 1
Case 5: iPosition = -1
End Select
If iPosition = -1 Then
DoCmd.GoToRecord acDataForm, Me.Name, acNewRec
Me!txtNoOfNos = "(New)"
Else
.MoveFirst
For i = 0 To .RecordCount - 1
If .AbsolutePosition = iPosition Then
BM = .Bookmark
iPosition = .AbsolutePosition + 1
Exit For
End If
.MoveNext
Next i
Me.Bookmark = BM
Me!txtNoOfNos = iPosition & "/" & .RecordCount
End If
iEnable = iPosition
End With
rs.Close
' routing to enable or disable the command buttons as required.
EnableDisableFor iEnable, iTotal
End Function
You ran replace
rs.MoveFirst
Do Until rs.EOF
If !ID = Me!ID Then
iPosition = .AbsolutePosition
Exit Do
ElseIf Nz(Me!ID, "") = "" Then
.MoveLast
iPosition = .RecordCount
iEnable = -1
Exit Do
End If
.MoveNext
Loop
With
.Bookmark = Me.Bookmark
iPosition = .AbsolutePosition
You ran replace
.MoveFirst
For i = 0 To .RecordCount - 1
If .AbsolutePosition = iPosition Then
BM = .Bookmark
iPosition = .AbsolutePosition + 1
Exit For
End If
.MoveNext
Next i
with
.AbsolutePosition = iPosition
BM = .Bookmark
Seems like a lot of work when this will to the same thing (with problem handling):
Function fnGoto(iConst As Integer)
With Me.Recordset
If Me.NewRecord Then
If iConst = 0 Then iConst = 2
If iConst = 1 Then iConst = 3
End If
Select Case iConst
Case 0: If .AbsolutePosition > 0 Then .MovePrevious
Case 1: If .AbsolutePosition < .RecordCount Then .MoveNext
Case 2: .MoveFirst
Case 3: .MoveLast
Case 5: DoCmd.GoToRecord acDataForm, Me.Name, acNewRec
End Select
If Me.NewRecord Then
Me!txtNoOfNos = "(New)"
Else
Me!txtNoOfNos = .AbsolutePosition + 1 & "/" & .RecordCount
End If
End With
End Function
Glad to help and thank you very much for the points with "A" grade!
Happy computing!
Nelson
Business Accounts
Answer for Membership
by: thenelsonPosted on 2009-11-03 at 13:14:53ID: 25733745
Lets make it simpler:
Function fnGoto(iConst As Integer)
Select Case iConst
Case 0 'previous
DoCmd.GoToRecord acDataForm, Me.Name, acPrevious
Case 1 'next
DoCmd.GoToRecord acDataForm, Me.Name, acNext
Case 2 'first
DoCmd.GoToRecord acDataForm, Me.Name, acFirst
Case 3 'last
DoCmd.GoToRecord acDataForm, Me.Name, acLast
Case 5 'new
DoCmd.GoToRecord acDataForm, Me.Name, acNewRec
End Select
End With
End Function