473,661 Members | 2,432 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to tell if you're on the last record

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
4 13270
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 AbsolutePositio n
property. In a code module, enter AbsolutePositio n and press F1

Sub AbsolutePositio nX()

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

Set dbsNorthwind = OpenDatabase("N orthwind.mdb")
' AbsolutePositio n only works with dynasets or snapshots.
Set rstEmployees = _
dbsNorthwind.Op enRecordset("Em ployees", _
dbOpenSnapshot)

With rstEmployees
' Populate Recordset.
.MoveLast
.MoveFirst

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

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

.Close
End With

dbsNorthwind.Cl ose

End Sub
Mar 9 '06 #2
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.co m> wrote in message
news:w2******** *********@newsr ead1.news.atl.e arthlink.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 AbsolutePositio n
property. In a code module, enter AbsolutePositio n and press F1

Sub AbsolutePositio nX()

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

Set dbsNorthwind = OpenDatabase("N orthwind.mdb")
' AbsolutePositio n only works with dynasets or snapshots.
Set rstEmployees = _
dbsNorthwind.Op enRecordset("Em ployees", _
dbOpenSnapshot)

With rstEmployees
' Populate Recordset.
.MoveLast
.MoveFirst

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

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

.Close
End With

dbsNorthwind.Cl ose

End Sub

Mar 9 '06 #3
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.RecordsetClo ne
Dim lngPos As Long
rst.MoveLast
lngPos = rst.RecordCoutn
rst.FindFirst "ID = " & Me.ID
If rst.AbsolutePos ition = lngPos then Msgbox "EOF"
....

or something similar.


Rick

"salad" <oi*@vinegar.co m> wrote in message
news:w2******** *********@newsr ead1.news.atl.e arthlink.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 AbsolutePositio n
property. In a code module, enter AbsolutePositio n and press F1

Sub AbsolutePositio nX()

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

Set dbsNorthwind = OpenDatabase("N orthwind.mdb")
' AbsolutePositio n only works with dynasets or snapshots.
Set rstEmployees = _
dbsNorthwind. OpenRecordset(" Employees", _
dbOpenSnapsho t)

With rstEmployees
' Populate Recordset.
.MoveLast
.MoveFirst

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

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

.Close
End With

dbsNorthwind. Close

End Sub


Mar 9 '06 #4
Perfect! Thanks!
"salad" <oi*@vinegar.co m> wrote in message
news:bk******** *********@newsr ead3.news.atl.e arthlink.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.RecordsetClo ne
Dim lngPos As Long
rst.MoveLast
lngPos = rst.RecordCoutn
rst.FindFirst "ID = " & Me.ID
If rst.AbsolutePos ition = lngPos then Msgbox "EOF"
...

or something similar.


Rick

"salad" <oi*@vinegar.co m> wrote in message
news:w2******** *********@newsr ead1.news.atl.e arthlink.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 AbsolutePositio n
property. In a code module, enter AbsolutePositio n and press F1

Sub AbsolutePositio nX()

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

Set dbsNorthwind = OpenDatabase("N orthwind.mdb")
' AbsolutePositio n only works with dynasets or snapshots.
Set rstEmployees = _
dbsNorthwind .OpenRecordset( "Employees" , _
dbOpenSnapsh ot)

With rstEmployees
' Populate Recordset.
.MoveLast
.MoveFirst

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

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

.Close
End With

dbsNorthwind .Close

End Sub



Mar 9 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2297
by: middletree | last post by:
http://www.middletree.net/debug/DisplaySortableTickets.html Doing an Intranet-based app in ASP. I put the view source version (that is, no ASP code) out on my personal site at the above URL to show you what I am looking at. Style sheet isn't there, but shouldn't matter in this case. My code says to show some things from the recordset based on certain criteria selected from the search page. In this scase, the search page is actually...
1
11739
by: Matt | last post by:
how to get the last record from database without looping? Whenever the user need to insert a new record to the database, it just increment the id field by one from the last record. I tried objRS.MoveLast, but it wont work.
3
2291
by: Daniel Ng | last post by:
Thanks for the 2 guys how hep to to solve to count the number of recount in forum. I'm done wif that. Got 1 more question.. Example Record 1: ID 2 VALUE 2 Record 2: ID 3 VALUE 3 Record 3: ID 2 VALUE 1 How can i retrieve the VALUE of the last record of ID 2 using ASP?? In this case, the asnwer given to me should be Record 3.
5
1945
by: SalimShahzad | last post by:
dear gurus, can any one help me to how to store progrmatically last value in combo box. say i load access form. but in combo box the last value how it will come any ideas...as i need only programatically regards,
2
3661
by: Randy | last post by:
I put a new record button on a form and I get a message that "you can not go to that record" Would someone tell me what is wrong. I put buttons on both the parent and child tables that go to first record, previous record, next record, and last record with no problem. Thanks for any help. I am new at Access. Using Access 2000.
3
2585
by: Mark | last post by:
I'm using ASP.Net to accress a database, what I need to do is get the fields out of the very last record in the db. How do I do this? Actually I'm after the primary key, titled 'AdID' it'll tell me what number this last record is. so I can tell what number the next record inserted will be. How do I do this? Thanks,
17
2520
by: michel.ank | last post by:
Hi, I'm using the class PrintLines and my last record of page aren't with the borders. Somebody can help me? Thanks,
1
5739
by: chris | last post by:
I have a Switchboard I created that has the program version at the bottom. I have a table with version history in it that I maintain everytime I make changes and release it to the users. Currently I have to update the switchboard field manually as it is an unbound text box. Is there a way that I can have the Field look for the last record in my version table and grab the version field? Thank you, Chris
23
29998
by: tshad | last post by:
Is there a way to know if you are looking at the last record record of foreach loop other then setting up a loop counter that you manually increment? foreach (Racecar racecar in RaceCarCollection) { ... if last row do something? }
0
8341
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8754
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8542
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8630
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7362
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4177
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4343
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1984
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.