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

How to tell if you're on the last record

P: n/a
Hi All,

Just wondering, in vb code, how to if the last record on a cascading form is
the current record?

Thanks!
Mar 9 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Rico wrote:
Hi All,

Just wondering, in vb code, how to if the last record on a cascading form is
the current record?

Thanks!

This is example code from the help file under the topic AbsolutePosition
property. In a code module, enter AbsolutePosition and press F1

Sub AbsolutePositionX()

Dim dbsNorthwind As Database
Dim rstEmployees As Recordset
Dim strMessage As String

Set dbsNorthwind = OpenDatabase("Northwind.mdb")
' AbsolutePosition only works with dynasets or snapshots.
Set rstEmployees = _
dbsNorthwind.OpenRecordset("Employees", _
dbOpenSnapshot)

With rstEmployees
' Populate Recordset.
.MoveLast
.MoveFirst

' Enumerate Recordset.
Do While Not .EOF
' Display current record information. Add 1 to

' AbsolutePosition value because it is zero-based.
strMessage = "Employee: " & !LastName & vbCr & _
"(record " & (.AbsolutePosition + 1) & _
" of " & .RecordCount & ")"
If MsgBox(strMessage, vbOKCancel) = vbCancel _
Then Exit Do
.MoveNext
Loop

.Close
End With

dbsNorthwind.Close

End Sub
Mar 9 '06 #2

P: n/a
Hi Salad,

I appreciate it, but I'm using a form with a bound recordset. I'd like to
be able to tell if the user is on the last record so when they update it, I
can set the focus to a command button rather than staying on the current
record (AllowAdditions is off).

Rick

"salad" <oi*@vinegar.com> wrote in message
news:w2*****************@newsread1.news.atl.earthl ink.net...
Rico wrote:
Hi All,

Just wondering, in vb code, how to if the last record on a cascading form
is the current record?

Thanks!

This is example code from the help file under the topic AbsolutePosition
property. In a code module, enter AbsolutePosition and press F1

Sub AbsolutePositionX()

Dim dbsNorthwind As Database
Dim rstEmployees As Recordset
Dim strMessage As String

Set dbsNorthwind = OpenDatabase("Northwind.mdb")
' AbsolutePosition only works with dynasets or snapshots.
Set rstEmployees = _
dbsNorthwind.OpenRecordset("Employees", _
dbOpenSnapshot)

With rstEmployees
' Populate Recordset.
.MoveLast
.MoveFirst

' Enumerate Recordset.
Do While Not .EOF
' Display current record information. Add 1 to

' AbsolutePosition value because it is zero-based.
strMessage = "Employee: " & !LastName & vbCr & _
"(record " & (.AbsolutePosition + 1) & _
" of " & .RecordCount & ")"
If MsgBox(strMessage, vbOKCancel) = vbCancel _
Then Exit Do
.MoveNext
Loop

.Close
End With

dbsNorthwind.Close

End Sub

Mar 9 '06 #3

P: n/a
Rico wrote:
Hi Salad,

I appreciate it, but I'm using a form with a bound recordset. I'd like to
be able to tell if the user is on the last record so when they update it, I
can set the focus to a command button rather than staying on the current
record (AllowAdditions is off).
The code can be modified to suit. First, set a recordset clone to the
form. Then get the record count. Then find out if the current record
is at the end.

Dim rst as recordset
set rst = Me.RecordsetClone
Dim lngPos As Long
rst.MoveLast
lngPos = rst.RecordCoutn
rst.FindFirst "ID = " & Me.ID
If rst.AbsolutePosition = lngPos then Msgbox "EOF"
....

or something similar.


Rick

"salad" <oi*@vinegar.com> wrote in message
news:w2*****************@newsread1.news.atl.earthl ink.net...
Rico wrote:
Hi All,

Just wondering, in vb code, how to if the last record on a cascading form
is the current record?

Thanks!


This is example code from the help file under the topic AbsolutePosition
property. In a code module, enter AbsolutePosition and press F1

Sub AbsolutePositionX()

Dim dbsNorthwind As Database
Dim rstEmployees As Recordset
Dim strMessage As String

Set dbsNorthwind = OpenDatabase("Northwind.mdb")
' AbsolutePosition only works with dynasets or snapshots.
Set rstEmployees = _
dbsNorthwind.OpenRecordset("Employees", _
dbOpenSnapshot)

With rstEmployees
' Populate Recordset.
.MoveLast
.MoveFirst

' Enumerate Recordset.
Do While Not .EOF
' Display current record information. Add 1 to

' AbsolutePosition value because it is zero-based.
strMessage = "Employee: " & !LastName & vbCr & _
"(record " & (.AbsolutePosition + 1) & _
" of " & .RecordCount & ")"
If MsgBox(strMessage, vbOKCancel) = vbCancel _
Then Exit Do
.MoveNext
Loop

.Close
End With

dbsNorthwind.Close

End Sub


Mar 9 '06 #4

P: n/a
Perfect! Thanks!
"salad" <oi*@vinegar.com> wrote in message
news:bk*****************@newsread3.news.atl.earthl ink.net...
Rico wrote:
Hi Salad,

I appreciate it, but I'm using a form with a bound recordset. I'd like
to be able to tell if the user is on the last record so when they update
it, I can set the focus to a command button rather than staying on the
current record (AllowAdditions is off).


The code can be modified to suit. First, set a recordset clone to the
form. Then get the record count. Then find out if the current record is
at the end.

Dim rst as recordset
set rst = Me.RecordsetClone
Dim lngPos As Long
rst.MoveLast
lngPos = rst.RecordCoutn
rst.FindFirst "ID = " & Me.ID
If rst.AbsolutePosition = lngPos then Msgbox "EOF"
...

or something similar.


Rick

"salad" <oi*@vinegar.com> wrote in message
news:w2*****************@newsread1.news.atl.earthl ink.net...
Rico wrote:

Hi All,

Just wondering, in vb code, how to if the last record on a cascading
form is the current record?

Thanks!

This is example code from the help file under the topic AbsolutePosition
property. In a code module, enter AbsolutePosition and press F1

Sub AbsolutePositionX()

Dim dbsNorthwind As Database
Dim rstEmployees As Recordset
Dim strMessage As String

Set dbsNorthwind = OpenDatabase("Northwind.mdb")
' AbsolutePosition only works with dynasets or snapshots.
Set rstEmployees = _
dbsNorthwind.OpenRecordset("Employees", _
dbOpenSnapshot)

With rstEmployees
' Populate Recordset.
.MoveLast
.MoveFirst

' Enumerate Recordset.
Do While Not .EOF
' Display current record information. Add 1 to

' AbsolutePosition value because it is zero-based.
strMessage = "Employee: " & !LastName & vbCr & _
"(record " & (.AbsolutePosition + 1) & _
" of " & .RecordCount & ")"
If MsgBox(strMessage, vbOKCancel) = vbCancel _
Then Exit Do
.MoveNext
Loop

.Close
End With

dbsNorthwind.Close

End Sub



Mar 9 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.