I came across the .AbsolutePosition property on MS Office Dev Center website and was curious as to its' importance.
I've been active on Bytes primarily as far as VBA/Access forums are concerned and often I see people post Do While loops, yet they don't contain .AbsolutePosition. There is always the same starting point
But I never see .AbsolutePosition.
That begs the question - when is a good time to use it, and what are its' uses?
If I'm being too vague - please let me know! Thanks
11 2661
I use it primarily to track the progress of a Loop as a percentage of Records processed, as in: - 'It is Zero based, so
-
(rst.AbsolutePosition/rst.RecordCount)
P.S. - Code obviously omitted.
NeoPa 32,556
Expert Mod 16PB
It's something that gives you the position of the current record within the recordset.
NB. This is not the relative position of the record in the table, as that is meaningless. It is also not 100% reliable, as other members have noticed. As ADezii has said, it can be useful for determining progress through a recordset.
@mcupito:
Here is another context for which .AbsolutePosition can be used. I forgot to mention that I also use it to pluck a Random Record from a Recordset, namely generating a Random Number between 1 and .RecordCount then setting .AbsolutePosition to it. -
Dim rst As ADODB.Recordset
-
-
Set rst = New ADODB.Recordset
-
rst.Open "tblCustomers", CurrentProject.Connection, adOpenKeyset
-
-
Debug.Print rst.Fields(0).Value
-
-
'Move approximately halfway into Recordset
-
rst.AbsolutePosition = 0.5 * rst.RecordCount
-
Debug.Print rst.Fields(0).Value
-
-
'Move to the 35th row
-
rst.AbsolutePosition = 35
-
Debug.Print rst.Fields(0).Value
-
-
rst.Close
-
Set rst = Nothing
Thanks for the examples, ADezii. Thanks for the reply, NeoPa.
That being said - are there foreseeable problems in this code : - DoCmd.Hourglass True
-
DoCmd.SetWarnings False
-
DoCmd.OpenQuery "CheckConfirmVestUpdateQry"
-
DoCmd.OpenQuery "CheckConfirmPytUpdateQry"
-
DoCmd.Hourglass False
-
DoCmd.SetWarnings True
-
-
With Recordset
-
If .AbsolutePosition = .RecordCount - 1 Then
-
'you are on the last record
-
DoCmd.GoToRecord , , acFirst
-
Me.Requery
-
Me!CheckConfirmEntryFrm.Requery
-
Me!CheckConfirmVestingFrm.Requery
-
Else
-
'you are on some other record
-
DoCmd.GoToRecord , , acNext
-
Me!CheckConfirmEntryFrm.Requery
-
End If
-
End With
I do not see a problem as long as: - The Recordset supports the AbsolutePosition Property, not all do.
- You obtain an 'exact' RecordCount by traversing the Recordset, namely:
- rst.MoveLast:rst.MoveFirst
- You do not use the Object Variable Recordset to refer to an actual Recordset as you have in Code Line# 8:
-
With Recordset
-
'code segment
-
End With
So for #3 you're suggesting something like: - Dim rs as DAO.Recordset
-
rs = (SELECT * FROM Table)
Instead of referring to the Recordset as just a Recordset Object?
I am referring to the use of the Reserved Word Recordset to refer to an actual Recordset Object. -
'Define Recordset rs
-
With rs
-
'Code segment
-
End With
-
NOT -
'Define Recordset Recordset
-
With Recordset
-
'Code segment
-
End With
-
NeoPa 32,556
Expert Mod 16PB
You cannot set a Recordset variable to SQL like that Mark. Even if it did make sense and have quotes around it to make a string, it would still not be valid code.
You need to open a recordset, and possibly pass the SQL string as a parameter.
Okay, I understand now.
Would this work then, NeoPa? - Set rs = db.OpenRecordset("SELECT * FROM Table")
NeoPa 32,556
Expert Mod 16PB
Fundamentally - yes.
db would have to be set to a valid, open, database. rs would have to be usable as a Recordset variable. Table would have to be a valid table name. "Table" isn't usable without the [] - but that's just the details.
Got it. Thanks for your time NeoPa and ADezii.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: RAY |
last post by:
Hi ,
my boss has asked I sit in on an interview this afternoon and that I create
some interview questions on the person's experience.
What is C++ used for and why would a company benefit from...
|
by: Peter Kirk |
last post by:
Hi there,
can someone tell me what exactly a "property" is in a C# class? As far as I
can see it is "two methods" - ie a getter and a setter for an instance
variable.
What is the difference...
|
by: sklett |
last post by:
I just found myself doing something I haven't before:
<code>
public uint Duration
{
get
{
uint duration = 0;
foreach(Thing t in m_things)
{
duration += t.Duration;
|
by: stephen |
last post by:
Hi,
I make use of properties to store values that are relevant to the page but
this time I am posting the page to itself and the values are Zero or null
(they disappear). is there any other way...
|
by: Franky |
last post by:
I think I misread a post and understood that if I do:
System.Windows.Forms.Cursor.Current = Cursors.WaitCursor
there is no need to reset the cursor to Default.
So I made all the reset...
|
by: superd052 |
last post by:
So I'm having a little trouble with the Recordset.AbsolutePosition property, and similarly, the RecordsetClone.AbsolutePosition property in Access 2007.
Here's what I'm trying to accomplish:
I...
|
by: Trompomerson |
last post by:
Hello guys,
I am running the script below and am able to load my recordset and cycle through the values in the fields. However I want to use the .AbsolutePosition property to help place the data...
|
by: SanjivaniPant |
last post by:
Hello,
if I set disabled to true for my frame then will it mean I am stopping the frame from tab ordering?
~Sanjivani
|
by: mk |
last post by:
It seems like getter is defined in such way that it passes only 'self':
class FunDict(dict):
def __init__(self):
self.fundict = dict()
def fget(self, fun):
return fundict
|
by: Seth Schrock |
last post by:
I have been studying VBA for Access, and the latest chapter was on class modules. So far, I think that I have a pretty good grasp on how to create one (at least for a beginner). However, the point...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
| |